080.亲密数

简介: 080.亲密数
#include<stdio.h>
void main()
{
    int a,i,b,n,m;
    clrscr();
    printf("================================================================\n");
    printf("     This is a program to find friendly numbers pair.\n");
    printf("   Which means the sum of integer A's all factors (except A)\n");
    printf("    equals to the sum of integer B's all factors (except B).\n");
    printf("     < e.g. sum of integer 6's all factors are:1+2+3=6 >\n");
    printf("================================================================\n");
    printf("\n Please input the scale you want to find n: ");
    scanf("%d",&n);
    printf("\n There are following friendly--numbers pair smaller than %d:\n",n);
    for(a=1;a<n;a++)        /*穷举1000以内的全部整数*/
    {
        for(b=0,i=1;i<=a/2;i++)    /*计算数a的各因子,各因子之和存放于b*/
            if(!(a%i))b+=i;        /*计算b的各因子,各因子之和存于m*/
        for(m=0,i=1;i<=b/2;i++)
            if(!(b%i))m+=i;
        if(m==a&&a<b)
            printf("%4d..%4d    ",a,b);     /*若n=a,则a和b是一对亲密数,输出*/
    }
    puts("\n\n Press any key to quit...");
    getch();
}
相关文章
|
4月前
|
C++
第三大的数(C++)
第三大的数(C++)
18 0
|
6月前
第三大的数
第三大的数
|
10月前
|
机器学习/深度学习
1361:产生数(Produce)
1361:产生数(Produce)
|
12月前
|
人工智能 运维 物联网
数智光伏,走在希望的田野上
数智光伏,走在希望的田野上
|
C++
完美数(C++)
对于一个 正整数,如果它和除了它自身以外的所有 正因子 之和相等,我们称它为 「完美数」。给定一个 整数 n, 如果是完美数,返回 true;否则返回 false。
125 0
|
C++
201312-4 有趣的数
201312-4 有趣的数
49 0
201312-4 有趣的数
ZCMU - 2047: 数的读法
ZCMU - 2047: 数的读法
86 0