import java.util.Scanner; public class row { static short[] tab ={ 0,1,4,9,16,25,36,49,64,81 }; static int[] tab_max = {0, 9, 97, 243, 324, 405, 486, 567, 648, 729, 810, 891, 972, 1053, 1134, 1215, 1296, 1377, 1458, 1539}; static long[] tab_start = {0, 1, 10, 100, 1000, 10000, 100000, 1000000L, 10000000L, 100000000L, 1000000000L, 10000000000L, 100000000000L, 1000000000000L, 10000000000000L, 100000000000000L, 1000000000000000L, 10000000000000000L, 100000000000000000L, 1000000000000000000L,999999999999999999L}; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String[] key = keyboard.nextLine().split(" "); long k = Long.parseLong(key[0]); long a = Long.parseLong(key[1]); long b = Long.parseLong(key[2]); long r = 0; if(a%k!=0) a = a + (k-a%k); int length = String.valueOf(a).length(); int max = tab_max[length]; while(a<=b) { if(getSumOfQuater(a) == a/k) { r++; } a+=k; if(a/k>max) { length = String.valueOf(a).length(); a=tab_start[length+1]; max = tab_max[length]; if(a%k!=0) a = a + (k-a%k); } } System.out.println(r); System.exit(0); } private static long getSumOfQuater(long value) { long result = 0; while (value > 0) { result += tab[(int) (value % 10)]; value = value / 10; } return result; } }
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 51 52 53 54 | import java.util.Scanner; public class row { static short[] tab ={ 0,1,4,9,16,25,36,49,64,81 }; static int[] tab_max = {0, 9, 97, 243, 324, 405, 486, 567, 648, 729, 810, 891, 972, 1053, 1134, 1215, 1296, 1377, 1458, 1539}; static long[] tab_start = {0, 1, 10, 100, 1000, 10000, 100000, 1000000L, 10000000L, 100000000L, 1000000000L, 10000000000L, 100000000000L, 1000000000000L, 10000000000000L, 100000000000000L, 1000000000000000L, 10000000000000000L, 100000000000000000L, 1000000000000000000L,999999999999999999L}; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String[] key = keyboard.nextLine().split(" "); long k = Long.parseLong(key[0]); long a = Long.parseLong(key[1]); long b = Long.parseLong(key[2]); long r = 0; if(a%k!=0) a = a + (k-a%k); int length = String.valueOf(a).length(); int max = tab_max[length]; while(a<=b) { if(getSumOfQuater(a) == a/k) { r++; } a+=k; if(a/k>max) { length = String.valueOf(a).length(); a=tab_start[length+1]; max = tab_max[length]; if(a%k!=0) a = a + (k-a%k); } } System.out.println(r); System.exit(0); } private static long getSumOfQuater(long value) { long result = 0; while (value > 0) { result += tab[(int) (value % 10)]; value = value / 10; } return result; } } |