import java.util.*; public class row { public static void main(String[] args) { Scanner s = new Scanner(System.in); String line = s.nextLine(); String[] arg = line.split(" "); long k = Long.parseLong(arg[0]); long a = Long.parseLong(arg[1]); long b = Long.parseLong(arg[2]); long temp = a; int count = 0; if (temp < k) temp = k; if (temp % k != 0){ long l = temp / k; temp = (l + 1) * k; } while (temp % k != 0){ temp++; } long div = temp / k; while (temp <= b){ long square = squareDigits(temp); if (k * square == temp){ //System.out.println(temp + " " + square + " " + k); count++; } temp += k; div++; if (div > 1600) break; } System.out.println(count); System.exit(0); } public static long squareDigits(long l){ long ret = 0L; String s = String.valueOf(l); //System.out.println(s); char[] t = s.toCharArray(); for (int i = 0; i < t.length; i++){ int digit = (int)t[i] - (int)'0'; ret += digit * digit; } return ret; } }
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 | import java.util.*; public class row { public static void main(String[] args) { Scanner s = new Scanner(System.in); String line = s.nextLine(); String[] arg = line.split(" "); long k = Long.parseLong(arg[0]); long a = Long.parseLong(arg[1]); long b = Long.parseLong(arg[2]); long temp = a; int count = 0; if (temp < k) temp = k; if (temp % k != 0){ long l = temp / k; temp = (l + 1) * k; } while (temp % k != 0){ temp++; } long div = temp / k; while (temp <= b){ long square = squareDigits(temp); if (k * square == temp){ //System.out.println(temp + " " + square + " " + k); count++; } temp += k; div++; if (div > 1600) break; } System.out.println(count); System.exit(0); } public static long squareDigits(long l){ long ret = 0L; String s = String.valueOf(l); //System.out.println(s); char[] t = s.toCharArray(); for (int i = 0; i < t.length; i++){ int digit = (int)t[i] - (int)'0'; ret += digit * digit; } return ret; } } |