0

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 カウンターを上げながら、新しいサイクルの開始点として前のサイクルの数値を繰り返さないようにするにはどうすればよいですか? また、許可されていないため、配列を使用することはできません。

4

0 に答える 0