X倍数问题
Time Limit:100 ms | Memory Limit:10000 KB
Submit:334 (167 users) | Accepted:155 (136 users)
Submit:334 (167 users) | Accepted:155 (136 users)
Description
若一个整数Y的个位数为X,将X移到最高位得到的恰好是Y的X倍,称Y为一个X倍数。例如,0是一个0倍数,1是一个1倍数。
Input
无
Output
请依次输出最小的0倍数、1倍数、2倍数、……9倍数。每个X倍数输出一行。
Sample Input
无
Sample Output
0 1 …… …… …… …… …… …… …… ……
Hint
即使是最小的X倍数也可能是一个非常大的整数,甚至远远超出int所能表达的范围。
#include<iostream>
using namespace std;
int main()
{
freopen("1.txt","w",stdout);
cout<<0<<endl;
cout<<1<<endl;
for(int n=2;n<=9;n++)
{
int x=n,y,t;
int a[1000],l=0;
while(1)
{
if(x%n==0&&x/n==n) break;
y=x/n;t=x%n;
a[l++]=y;
x=t*10+y;
}
for(int i=0;i<l;i++) cout<<a[i];cout<<n<<endl;
}
return 0;
}
using namespace std;
int main()
{
freopen("1.txt","w",stdout);
cout<<0<<endl;
cout<<1<<endl;
for(int n=2;n<=9;n++)
{
int x=n,y,t;
int a[1000],l=0;
while(1)
{
if(x%n==0&&x/n==n) break;
y=x/n;t=x%n;
a[l++]=y;
x=t*10+y;
}
for(int i=0;i<l;i++) cout<<a[i];cout<<n<<endl;
}
return 0;
}