惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

飞絮落叶雪 - 编程

我让 Ai 写了一个记账本 1011-空心六边形 1149 - 回文数个数 1071 - 字符图形7-星号菱形 1140 - 亲密数对 1138 - 求无暇素数 1136 - 输出m和n范围内的完全数(完美数) 1151-桐桐数
1089 - 找数字
Mr.He · 2024-06-13 · via 飞絮落叶雪 - 编程

1089找数字.jpg

思路

1、遍历每个数位;
2、根据题目中的条件写出判断;
3、输出数字。

知识点:

1、几层嵌套if,要准确细心完成,不能输错符号;
2、练习嵌套循环的用法。

代码实现

# include <iostream>
# include <cmath>
using namespace std;

//定义一个判断质数的函数
int isPrime(int x) {
    int i;
    if (i == 2) {
        bool prime = true;
    }
    bool prime = true;
    for(i = 2; i <= sqrt(x); i++) {
        if(x % i == 0) {
            prime = false;
            break;
        }
    }
    return prime;
}

int main() {
    int g, s, b;
    //遍历百位上的数字1-9
    for(b = 1; b <= 9; b++) {
        //遍历十位上的数字0-9
        for(s = 0; s <= 9; s++) {
            //遍历个位上的数字
            for(g = 0; g <= 9; g++) {
                //各数位不同
                if(b != s && s != g && g != b) {
                    //十位上的数字大于百位和个位上的数字之和
                    if(g + b < s) {
                        //十位和百位之和不是质数
                        if(isPrime(s + b) == false) {
                            //符合以上条件输出数字
                            cout << b * 100 + s * 10 + g << endl;
                        }
                    }
                }
            }
        }
    }

    return 0;
}