[ZJd044][UVA640] Self Numbers
題目:
http://zerojudge.tw/ShowProblem?problemid=d044
-----------------------------------------------------------------------------------------------------------
#include<bits/stdc++.h>
#define maxn 1000000+1
using namespace std;
int a[maxn] = {0};
int main()
{
int x = 0, j = 0;
for(int i=1;i<maxn;i++)
{
j = i;
if(a[j] == 0)
{
while(1)
{
x = j;
while(j > 0)
{
x += j % 10;
j = j / 10;
}
if(x < maxn && a[x] == 0)
{
a[x] = 1;
j = x;
}
else
break;
}
}
}
for(int i=1;i<maxn;i++)
if(a[i] == 0)
printf("%d\n",i);
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=d044
-----------------------------------------------------------------------------------------------------------
#include<bits/stdc++.h>
#define maxn 1000000+1
using namespace std;
int a[maxn] = {0};
int main()
{
int x = 0, j = 0;
for(int i=1;i<maxn;i++)
{
j = i;
if(a[j] == 0)
{
while(1)
{
x = j;
while(j > 0)
{
x += j % 10;
j = j / 10;
}
if(x < maxn && a[x] == 0)
{
a[x] = 1;
j = x;
}
else
break;
}
}
}
for(int i=1;i<maxn;i++)
if(a[i] == 0)
printf("%d\n",i);
return 0;
}
留言
張貼留言