Skip to content

Instantly share code, notes, and snippets.

@EragonJ
Created November 25, 2009 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EragonJ/242673 to your computer and use it in GitHub Desktop.
Save EragonJ/242673 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
int check(int);
int main(){
int i,j,k;
int c=0;
while(scanf("%d %d",&i,&j)==2){
if(j>=i){
if(c==0){
c=1;
}else{
printf("\n");
}
for(k=i;k<=j;k++){
if(check(k)){
printf("%d %d\n",k,check(k));
}
}
}
}
return 0;
}
int check(int in){
int i,count=0;
int sum=0;
int n = in;
int array[50];
if(n==1){
return 1;
}
while(sum!=1){
array[count++] = n;
sum = 0;
for(i=10;(n/i)!=0||(n%i)!=0;){
sum += (n%i)*(n%i);
n/=i;
}
n = sum;
for(i=0;i<count;i++){
if((array[i]==sum)){
return 0;
}
}
}
sum = 0; //Some problems happened here in Mac
return count+1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment