/* #include <iostream> using namespace std; int main(void){ int data[3][6001]={0}; int j=1; for(int j=0;j<5000;j++){ int a=j; int sum=j; while(j!=0){ sum+=j%10; j=j/10; } data[0][sum]++; if(data[0][sum]>2)data[0][sum]=2; data[data[0][sum]][sum]=a; } int num=0; int sumofself=0; int sumofdup=0; int map[500]={0}; cout<<"Print self numbers:"<<endl; for(int i=0;i<5000;i++){ if(data[0][i]==0){ sumofself+=i; cout<<i<<" "; } if(data[0][i]>=2){ sumofdup+=i; num++; map[i]++; } } cout<<endl; cout<<"Sum of self numbers:"<<sumofself<<endl; cout<<endl; cout<<"duplicate generator numbers:"<<endl; cout<<endl; cout<<"Yotal duplicate numbers:"<<num<<endl; cout<<endl; for(int i=1;i<num;i++){ printf("%d: ",map[i]); printf(" %d",data[1][i]); printf(" %d\n",data[2][i]); } } /* #include<iostream> using namespace std; int fun(int a); int main(void){ int data[6001]={0}; for(int i=1;i<5000;i++){ data[fun(i)]++; } int num=0; int sum1=0; cout<<"Print self numbers:"<<endl; for(int i=1;i<5000;i++){ if(data[i]==0){ cout<<" "<<i; sum1+=i; } if(data[i]>=2){ num++; } } cout<<endl; cout<<"Sum of self numbers:"<<sum1<<endl; cout<<endl; cout<<"duplicate generator numbers"<<endl; cout<<endl; cout<<"Total duplicate numbers:"<<num<<endl; system("pause"); } int fun(int a){ int data[4]={0}; int index=0; int temp=a; while(a!=0){ data[index++]=a%10; a/=10; } return temp+data[0]+data[1]+data[2]+data[3]; }*/ #include <stdio.h> int Gen[3][5000]={0}; int sum=0; int Num=0; int SelfNum=0; int Dup[5000]={0}; int DupNum=0; int temp=0; int main(int argc, char* argv[]) { for(int test=1;test<5000;test++) { temp=test; sum=test; while(temp>=10) { sum+=(temp%10); temp=temp/10; } sum+=temp; if(sum>4999) break; Gen[0][sum]++; if(Gen[0][sum]>2) Gen[0][sum]=2; Gen[Gen[0][sum]][sum]=test; sum=0; } for(Num=1;Num<5000;Num++) { if(Gen[0][Num]==0) { printf("%d ",Num); SelfNum+=Num; } if(Gen[0][Num]>1) { DupNum++; //printf("!!!%d ",Num); Dup[DupNum]=Num; } } printf("\n%d",SelfNum); //Now you have done all self numbers! printf("\n%d\n",DupNum); for(int Num=1;Num<DupNum;Num++) //for(int Num=1;Num<5;Num++) { printf("%d: ",Dup[Num]); printf(" %d",Gen[1][Dup[Num]]); printf(" %d\n",Gen[2][Dup[Num]]); } while(1); return 0; }