import java.util.Scanner; public class row { private static int k; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); k = Integer.parseInt(scanner.next()); long min = Long.parseLong(scanner.next()); long max = Long.parseLong(scanner.next()); int result = 0; for (long i = min; i < max; i++) { if (i % k == 0 && rowCalculate(i)){ result++; } } System.out.println(result); } private static boolean rowCalculate(long i) { int powSum = 0; long orig = i; for (long j = 1; j < Math.pow(10,18); j = j*10){ long mod = (i % j*10) / j ; powSum += Math.pow(mod, 2); i -= mod; } return k * powSum == orig; } }
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 | import java.util.Scanner; public class row { private static int k; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); k = Integer.parseInt(scanner.next()); long min = Long.parseLong(scanner.next()); long max = Long.parseLong(scanner.next()); int result = 0; for (long i = min; i < max; i++) { if (i % k == 0 && rowCalculate(i)){ result++; } } System.out.println(result); } private static boolean rowCalculate(long i) { int powSum = 0; long orig = i; for (long j = 1; j < Math.pow(10,18); j = j*10){ long mod = (i % j*10) / j ; powSum += Math.pow(mod, 2); i -= mod; } return k * powSum == orig; } } |