import java.util.Scanner; public class row { public static void main(String[] args) { Scanner s = new Scanner(System.in); long k = s.nextLong(); long a = s.nextLong(); long b = s.nextLong(); while (a % k != 0) { a++; } int result = 0; for (long i = a; i <= b; i += k) { long target = i / k; if (target == sumOfSquares(i)) { result ++; } } System.out.println(result); } static long sumOfSquares(long i) { long result = 0; while (i > 0) { int digit = (int) (i % 10); result += digit * digit; i = i / 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 | import java.util.Scanner; public class row { public static void main(String[] args) { Scanner s = new Scanner(System.in); long k = s.nextLong(); long a = s.nextLong(); long b = s.nextLong(); while (a % k != 0) { a++; } int result = 0; for (long i = a; i <= b; i += k) { long target = i / k; if (target == sumOfSquares(i)) { result ++; } } System.out.println(result); } static long sumOfSquares(long i) { long result = 0; while (i > 0) { int digit = (int) (i % 10); result += digit * digit; i = i / 10; } return result; } } |