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

推荐订阅源

The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
B
Blog
小众软件
小众软件
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
I
InfoQ
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
H
Help Net Security
雷峰网
雷峰网
S
SegmentFault 最新的问题
V
Visual Studio Blog
爱范儿
爱范儿

飞絮落叶雪 - 编程

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