Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C语言中的输出自守数_C - Fatal编程技术网

C语言中的输出自守数

C语言中的输出自守数,c,C,我需要输出10个自守数字,每行5个。 我写了下面的代码,但它不正确,你能帮我吗? 我需要输出的自守数字:“1,5,6,25,76, 376625937690625109376” int n=10,m=10,a,b,c; 对于(n=1;nb){ b=b*m; } a=(n*n)%b; 如果(a==n) { printf(“%d”,n); 如果(n%6==0) printf(“\n”); } a++; 有趣的问题 这是我想到的 #include <stdio.h> #include &l

我需要输出10个自守数字,每行5个。 我写了下面的代码,但它不正确,你能帮我吗? 我需要输出的自守数字:“1,5,6,25,76, 376625937690625109376”

int n=10,m=10,a,b,c;
对于(n=1;n<11;n++){
b=m;
而(n>b){
b=b*m;
}
a=(n*n)%b;
如果(a==n)
{
printf(“%d”,n);
如果(n%6==0)
printf(“\n”);
}
a++;
有趣的问题

这是我想到的

#include <stdio.h>
#include <math.h>
#include <limits.h>

int main()
{
    int counter = 0;
    int i=1;
    while(counter < 10)
    {
        if (i*i % (int)pow(10,(int)log10(i)+1) == i)
        {
            counter++;
            printf("%d) %d is automorphic because %d * %d == %d\n", counter, i, i, i, i*i);
        }
        ++i;
    }
    return 0;
}

(由于时间限制,我在找到8个值后停止)

什么是自守数?你得到了什么输出?你的#includes在哪里?Where is
main
?最后两个术语在平方时不适合32位
int
。@Jabberwocky数字的平方以相同的数字结尾。例如25*25=625,这是一个自守数。尝试使用
n
作为r所需输出的数量和作为自同构测试中的数字似乎是个坏主意。@WeatherVanethanks,但OP的工作是将此信息放入问题中。有趣的是。一个优化是数字只能以0、1、5或6结尾。如果考虑最后两位数字,则只有以00、01、25和76 n结尾的数字需要进行测试。
#include <stdio.h>
#include <math.h>
#include <limits.h>

int main()
{
    int counter = 0;
    int i=1;
    while(counter < 10)
    {
        if (i*i % (int)pow(10,(int)log10(i)+1) == i)
        {
            counter++;
            printf("%d) %d is automorphic because %d * %d == %d\n", counter, i, i, i, i*i);
        }
        ++i;
    }
    return 0;
}
Success #stdin #stdout 0s 4516KB
1) 1 is automorphic because 1 * 1 == 1
2) 5 is automorphic because 5 * 5 == 25
3) 6 is automorphic because 6 * 6 == 36
4) 25 is automorphic because 25 * 25 == 625
5) 76 is automorphic because 76 * 76 == 5776
6) 376 is automorphic because 376 * 376 == 141376
7) 625 is automorphic because 625 * 625 == 390625
8) 9376 is automorphic because 9376 * 9376 == 87909376