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

推荐订阅源

B
Blog
D
Docker
J
Java Code Geeks
腾讯CDC
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
M
MIT News - Artificial intelligence
L
LangChain Blog
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
博客园 - Franky
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
N
Netflix TechBlog - Medium
B
Blog RSS Feed
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News

飞絮落叶雪 - 编程

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

1140亲密数对.jpg

思路

  • 遍历M N求出它们的因子之和再比较
  • 输出

知识点

  • 复习巩固求一个数因子之和的方法(不含1和它本身)
  • 函数知识

代码实现

#include <iostream>
using namespace std;

//定义函数,求一个数的因数之和(不含1和它本身)
int yinzi(int x ) {
    int i, c = 0;
    for(i = 2; i * i &lt;= x; i++) {
        if(x % i == 0) {
            if(x / i != i) {
                c = c + i + x / i;
            } else {
                c = c + i;
            }
        }
    }
    return c;
}


int main() {
    int n;
    cin &gt;&gt; n;
    //遍历M
    for (int i = 2; i &lt; n; i++) {
        //遍历N
        for (int  j = 2; j &lt; n; j++) {
            //条件判断
            if(i != j) {
                if(yinzi(i) == j and yinzi(j) == i) {
                    cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; j &lt;&lt; endl;
                }
            }
        }
    }
}