実行できません
Posted: 2012年4月16日(月) 19:27
ここまでやったのですが、わからないので教えてください
問題はx=17846とすると、x^2+x=318497562となって、1〜9の数字を丁度一個ずつ含む9桁の整数となる。x^2+xが上記のような性質を満たす整数xをすべて求めよ
#include<stdio.h>
int main(void)
{
int y,x,a,b,c,d,e,f,g,h,i,m=0;
for(x=10000;x<31623;x++)
{
y=x*x+x;
a=y/100000000;
b=(y-a*100000000)/10000000;
c=(y-a*100000000-b*10000000)/1000000;
d=(y-a*100000000-b*10000000-c*1000000)/100000;
e=(y-a*100000000-b*10000000-c*1000000-d*100000)/10000;
f=(y-a*100000000-b*10000000-c*1000000-d*100000-e*10000)/1000;
g=(y-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000)/100;
h=(y-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000-g*100)/10;
i=y-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000-g*100-h*10;
if(a==1 || b==1 || c==1 || d==1 || e==1 || f==1 || g==1 || h==1 || i==1)
m++;
if(a==2 || b==2 || c==2 || d==2 || e==2 || f==2 || g==2 || h==2 ||i==2)
m++;
if(a==3 || b==3 || c==3 || d==3 || e==3 || f==3 || g==3 || h==3 || i==3)
m++;
if(a==4 || b==4 || c==4 || d==4 || e==4 || f==4 || g==4 || h==4 || i==4)
m++;
if(a==5 || b==5 || c==5 || d==5 || e==5 || f==5 || g==5 || h==5 || i==5)
m++;
if(a==6 || b==6 || c==6 || d==6 || e==6 || f==6 || g==6 || h==6 || i==6)
m++;
if(a==7 || b==7 || c==7 || d==7 || e==7 || f==7 || g==7 || h==7 || i==7)
m++;
if(a==8 || b==8 || c==8 || d==8 || e==8 || f==8 || g==8 || h==8 || i==8)
m++;
if(a==9 || b==9 || c==9 || d==9 || e==9 || f==9 || g==9 || h==9 || i==9)
m++;
if(m==9)
printf("%d\n",x);
}
return(0);
}
問題はx=17846とすると、x^2+x=318497562となって、1〜9の数字を丁度一個ずつ含む9桁の整数となる。x^2+xが上記のような性質を満たす整数xをすべて求めよ
#include<stdio.h>
int main(void)
{
int y,x,a,b,c,d,e,f,g,h,i,m=0;
for(x=10000;x<31623;x++)
{
y=x*x+x;
a=y/100000000;
b=(y-a*100000000)/10000000;
c=(y-a*100000000-b*10000000)/1000000;
d=(y-a*100000000-b*10000000-c*1000000)/100000;
e=(y-a*100000000-b*10000000-c*1000000-d*100000)/10000;
f=(y-a*100000000-b*10000000-c*1000000-d*100000-e*10000)/1000;
g=(y-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000)/100;
h=(y-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000-g*100)/10;
i=y-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000-g*100-h*10;
if(a==1 || b==1 || c==1 || d==1 || e==1 || f==1 || g==1 || h==1 || i==1)
m++;
if(a==2 || b==2 || c==2 || d==2 || e==2 || f==2 || g==2 || h==2 ||i==2)
m++;
if(a==3 || b==3 || c==3 || d==3 || e==3 || f==3 || g==3 || h==3 || i==3)
m++;
if(a==4 || b==4 || c==4 || d==4 || e==4 || f==4 || g==4 || h==4 || i==4)
m++;
if(a==5 || b==5 || c==5 || d==5 || e==5 || f==5 || g==5 || h==5 || i==5)
m++;
if(a==6 || b==6 || c==6 || d==6 || e==6 || f==6 || g==6 || h==6 || i==6)
m++;
if(a==7 || b==7 || c==7 || d==7 || e==7 || f==7 || g==7 || h==7 || i==7)
m++;
if(a==8 || b==8 || c==8 || d==8 || e==8 || f==8 || g==8 || h==8 || i==8)
m++;
if(a==9 || b==9 || c==9 || d==9 || e==9 || f==9 || g==9 || h==9 || i==9)
m++;
if(m==9)
printf("%d\n",x);
}
return(0);
}