Posted: Tue May 08, 2007 3:10 pm
Look the intervals of the Self Numbers. You may notice that there is a pattern ..
thanksrio wrote:Look the intervals of the Self Numbers. You may notice that there is a pattern ..
Code: Select all
Deleted After accepted
Code: Select all
mistake found.
Code: Select all
AC code removed by moderator!
You shouldn't post an accepted solution in the board. Please remove your code.
Code: Select all
640`s pdf is not same with problem
Code: Select all
#include<stdio.h>
#define max 1000001
char a[max];
long digit(long n)
{
int sum=0;
while(n!=0)
{
sum+=(n%10);
n=n/10;
}
return sum;
}
int main()
{
long i,n,k,d;
for(i=1;i<=max;i++)a[i]=1;
for(i=1;i<=max;)
{
k=i;
while(1)
{
d=k+digit(k);
if((d>=max)||!a[d])
break;
a[d]=0;
k=d;
}
for(i++;!a[i];i++) ;
}
for(i=1;i<max;i++)
if(a[i]){
printf("%ld\n",i);
}
return 0;
}
Code: Select all
1) Use an array and make sure the global declaration of the array so that the indexed value preset as zero.
2) Now start a loop from index i=1 to i=1000000.
3) If sum=i+digitsum of i, then set array[sum]=1.
4) Now just print the value of array indexed with zero.
Code: Select all
import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
import java.lang.*;
class Main
{
public static void main(String args[])
{
setNumbers();
}
public static void setNumbers()
{
int[] numbers=new int[1000000];
for(int i=1;i< 1000000;i++){
int temp = i+i%10+(i/10)%10+(i/100)%10+i/1000000;
if(temp< 1000000)
numbers[temp]=1;
}
for(int i=1;i< 1000000;i++){
if(numbers[i]==0)
System.out.println(i);
}
}
}