题目1060:完数VS盈数

来源:互联网 发布:python panda股票分析 编辑:程序博客网 时间:2024/05/05 04:09

转运四方海淘网 : zysfht.com

题目描述:

一个数如果恰好等于它的各因子(该数本身除外)子和,如:6=3+2+1。则称其为“完数”;若因子之和大于该数,则称其为“盈数”。
求出2到60之间所有“完数”和“盈数”。

输入:

题目没有任何输入。

输出:

输出2到60之间所有“完数”和“盈数”,并以如下形式输出:
E: e1 e2 e3 ......(ei为完数)
G: g1 g2 g3 ......(gi为盈数)
其中两个数之间要有空格,行尾不加空格。

样例输入:
样例输出:
来源:

2000年清华大学计算机研究生机试真题



#include<stdio.h>#include<stdlib.h>#include<math.h>int main(){    int i,j,count,temp,ycount=0,wcount=0;    int yinzi[60],yingshu[60],wanshu[60];    for(i=2;i<=60;i++)    {        count=0,temp=0;        for(j=1;j<i;j++)        {            if(i%j==0)             {                yinzi[count]=j;                count++;            }        }        for(j=0;j<count;j++)            temp+=yinzi[j];        if(temp==i)        {            wanshu[wcount]=i;            wcount++;        }        if(temp>i)        {                         yingshu[ycount]=i;            ycount++;        }     }    printf("E: ");    for(j=0;j<wcount-1;j++)        printf("%d ",wanshu[j]);    printf("%d\nG: ",wanshu[wcount-1]);    for(j=0;j<ycount-1;j++)        printf("%d ",yingshu[j]);    printf("%d\n",yingshu[ycount-1]);     return 0;} /**************************************************************    Problem: 1060    Language: C    Result: Accepted    Time:0 ms    Memory:908 kb****************************************************************/


0 0
原创粉丝点击