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

推荐订阅源

爱范儿
爱范儿
Y
Y Combinator Blog
博客园 - Franky
D
Docker
B
Blog RSS Feed
M
MIT News - Artificial intelligence
雷峰网
雷峰网
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
S
SegmentFault 最新的问题
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
B
Blog
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
Vercel News
Vercel News
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News

飞絮落叶雪 - 编程

我让 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;
}