#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char a[100];
long int n,i,j,k,l,sum,p,q;
while(scanf("%ld",&l))
{
for(i=0; i<pow(10,l); i++)
{
if(l==2)
sum=((i/10)+(i%10))*((i/10)+(i%10));
else if(l==4)
sum=((i/100)+(i%100))*((i/100)+(i%100));
else if(l==8)
sum=((i/10000)+(i%10000))*((i/10000)+(i%10000));
if(sum==i)
{
itoa(i,a,100);
j=strlen(a);
for(k=0; k<l-j; k++)
printf("0");
for(k=0; k<j; k++)
a[k]=a[k]+48;
puts(a);
}
}
}
return 0;
}
我不明白这个输出是什么。我试图找出奇怪的数字。我是初学者。请帮助。 关于quirksome号码: 数字3025有一个非常奇怪的怪癖:如果你把它的十进制表示分成两个相等的字符串 长度(30和25)和平方所得数字的总和,你得到原始数字:
(30 + 25) 2 = 3025
答案 0 :(得分:0)
也许您从其他地方获得了此代码,并且您想了解它的作用。
它要求<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3>inline editing with contenteditable & jquery</h3>
<div class="box">
<span class="edit">edit</span>
<span class="save">save</span>
<div class="text">
Hover this box and click on edit! - You can edit me then.
<br>When you finished - click save and you saved it.
</div>
</div>
,这将是数字的长度。 l
必须为2,4或8(代码不会检查此内容)。
对于从1到10的每个值l
到i
的幂,它将数字分成两部分,然后执行&#34; quirksome&#34;计算到l
。
如果总和等于当前sum
,则它是一个奇怪的数字并打印出来。打印有点奇怪,忘记了字符串i
。 (a
之前必须有puts(a);
)。可以使用a[k]=0;
答案 1 :(得分:0)
看看这段代码 - brutforce finder。很容易让它更快,但我留给你。我使用过microsoft特定的函数,但很容易将它改为C库实现的
int isQuirksome(unsigned long long number)
{
int result = 0, len;
char strnumber[50], first[50], second[50];
if (number < 10ULL) result = -1;
if (result != -1)
{
_ui64toa(number, strnumber, 10); // microsoft specific use the one from your library
len = strlen(strnumber);
result = 0;
for (int i = 1; i < len; i++)
{
unsigned long long FirstValue, SecondValue, sum;
strncpy(first, strnumber, i);
strncpy(second, strnumber + i, len - i);
first[i] = 0;
second[len - i] = 0;
FirstValue = _strtoui64(first, NULL, 10);
SecondValue = _strtoui64(second, NULL, 10);
sum = FirstValue + SecondValue;
if ((sum * sum) == number)
{
result = i;
break;
}
}
}
return result;
}
int main(int argc, char **argv)
{
char result[50];
for (unsigned long long i = 10; i < ULLONG_MAX; i++)
{
int pos;
if ((pos = isQuirksome(i)) > 0)
{
printf("Found !!!! %llu is the QuikSome Number position of the split is %d\n", i, pos);
}
}
}
和一些结果:
Found !!!! 81 is the QuikSome Number position of the split is 1
Found !!!! 100 is the QuikSome Number position of the split is 2
Found !!!! 2025 is the QuikSome Number position of the split is 2
Found !!!! 3025 is the QuikSome Number position of the split is 2
Found !!!! 9801 is the QuikSome Number position of the split is 2
Found !!!! 10000 is the QuikSome Number position of the split is 3
Found !!!! 88209 is the QuikSome Number position of the split is 2
Found !!!! 494209 is the QuikSome Number position of the split is 3
Found !!!! 998001 is the QuikSome Number position of the split is 3
Found !!!! 1000000 is the QuikSome Number position of the split is 4
Found !!!! 4941729 is the QuikSome Number position of the split is 3
Found !!!! 7441984 is the QuikSome Number position of the split is 3
Found !!!! 23804641 is the QuikSome Number position of the split is 3
Found !!!! 24502500 is the QuikSome Number position of the split is 4
Found !!!! 25502500 is the QuikSome Number position of the split is 4
Found !!!! 28005264 is the QuikSome Number position of the split is 2
Found !!!! 52881984 is the QuikSome Number position of the split is 4
Found !!!! 60481729 is the QuikSome Number position of the split is 4
Found !!!! 99980001 is the QuikSome Number position of the split is 4
Found !!!! 100000000 is the QuikSome Number position of the split is 5