C计算完美,友好和善于交际的数字

时间:2016-11-08 18:32:06

标签: c perfect-numbers sociable

我正在使用Dev C ++ ,程序运行时没有错误。我遇到的问题是它重复了之前周期中的数字,而我没有有效的方法来计算这些数字中有多少是完美的,友好的还是善于交际的。
这是主要计划:

int main()
{
    int per = 0, cyc = 0, ami = 0, rep = 0;
    for(int n = 2; n < MAXNUM; n++){
        int f = 0;
        for(int c = 1; !f  && c <= MAXCYC; c++){
            rep = c;
            long a = n;
            while(rep--) a = divs(a);
            rep = c;

            if(n == a ){
                printf("Cycle of length %d: %d", c, n);
                while(rep --){
                    a = divs(a);
                    printf(" %ld", a);
                    cyc++;
                }
                printf("\n");
                f = 1;
            }
        }
    }

    printf("\nFound %d cycles including \n", cyc);
    printf("%d cycles with perfect numbers and \n", per);
    printf("%d cycles with amicable numbers\n", ami);

    return 0;
}

如何让我的per和ami计数器上升时,它不会重复以前周期中的数字作为新周期的起点?我也不能使用数组,因为我不允许这样做。

0 个答案:

没有答案