import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class row { public static void main(String args[]) throws IOException{ BufferedReader inn = new BufferedReader(new InputStreamReader(System.in)); String[] arg = inn.readLine().split(" "); long k = Long.valueOf(arg[0]); long a = Long.valueOf(arg[1]); long b = Long.valueOf(arg[2]); inn.close(); int result = 0; long maxCount=1458; long minCount=1; long digits = b; if(k*1458>b){ maxCount = b/k; } if(k*1<a){ minCount=a/k+1; } for(long i=minCount; i<maxCount; i++){ digits=k*i; long sum=0; long rest=0; while(digits>0){ rest = digits%10; sum += rest*rest; digits /= 10; } if(sum==i){ result++; } } System.out.println(result); System.exit(0); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class row { public static void main(String args[]) throws IOException{ BufferedReader inn = new BufferedReader(new InputStreamReader(System.in)); String[] arg = inn.readLine().split(" "); long k = Long.valueOf(arg[0]); long a = Long.valueOf(arg[1]); long b = Long.valueOf(arg[2]); inn.close(); int result = 0; long maxCount=1458; long minCount=1; long digits = b; if(k*1458>b){ maxCount = b/k; } if(k*1<a){ minCount=a/k+1; } for(long i=minCount; i<maxCount; i++){ digits=k*i; long sum=0; long rest=0; while(digits>0){ rest = digits%10; sum += rest*rest; digits /= 10; } if(sum==i){ result++; } } System.out.println(result); System.exit(0); } } |