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

推荐订阅源

N
News | PayPal Newsroom
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
Apple Machine Learning Research
Apple Machine Learning Research
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
Cloudbric
Cloudbric
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Know Your Adversary
Know Your Adversary
A
Arctic Wolf
L
LangChain Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
小众软件
小众软件
NISL@THU
NISL@THU
云风的 BLOG
云风的 BLOG
P
Privacy & Cybersecurity Law Blog
S
Security @ Cisco Blogs
博客园 - 【当耐特】
I
InfoQ
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
O
OpenAI News
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
量子位
宝玉的分享
宝玉的分享

飞絮落叶雪 - 编程

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

老何最近在学习c++,发现很有趣,跟着学了一些基础知识,能够解决一些简单的问题,有点成就感。

问题描述.png

思路:

1、把这个数分解因数。 2、依次判断这些因数是否质数。 3、根据判断返回对应的语句。 ### 知识点:

1、一个非质数必定有一个因数小于它的平方根。 2、函数的定义,以及函数中再引用函数。 3、bool类型数据的使用方法。 4、综合利用所学知识解决问题。 ### 代码实现:

<pre class="io-enlighter-pre">```
#include <iostream> 
#include <cmath> 
using namespace std; //定义函数判断是否质数,如果是返回true 

int isPrime(long long x) { 
    long long i; bool isPrime = true; //平方根的第一种表示方法 
    for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
    isPrime = false; 
    break; // 一旦找到一个因子,就可以确定不是质数 }
    } 
return isPrime; 
} //定义函数遍历每一个因数,如果全是是质数返回true 

int yinshu(long long n) { 
    long long i; //假设因子是质数,如果假设因子是非因数也可。 
    bool prime = true; //平方根的第二种表示方法 
    for(i = 2; i * i <= n; i++) { 
        if(n % i == 0) { 
            if (isPrime(i) and isPrime(n / i)) { 
            continue; 
            } else { 
            prime = false; break; 
            }
        } 
    } 
    return prime; 
} 

int main() { 
    long long n; 
    cin >> n; 
    if(yinshu(n)) { 
    cout << It's a Tongtong number. << endl; 
    } else { 
    cout << It's not a Tongtong number. << endl; }
    return 0; 
    }