Created
November 25, 2009 12:28
-
-
Save EragonJ/242673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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