import java.util.*; import java.lang.*; import java.io.*; class row { public static int sumDigits(int number) { int result = 0; String numberStr = String.valueOf(number); for (int i = 0; i < numberStr.length(); i++) { int digit = Character.getNumericValue(numberStr.charAt(i)); result += digit * digit; } return result; } public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); int k = in.nextInt(); int a = in.nextInt(); int b = in.nextInt(); int count = 0; for (int i = a; i <= b; i++) { if (sumDigits(i) * k == i) { count++; } } System.out.println(count); } }
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 | import java.util.*; import java.lang.*; import java.io.*; class row { public static int sumDigits(int number) { int result = 0; String numberStr = String.valueOf(number); for (int i = 0; i < numberStr.length(); i++) { int digit = Character.getNumericValue(numberStr.charAt(i)); result += digit * digit; } return result; } public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); int k = in.nextInt(); int a = in.nextInt(); int b = in.nextInt(); int count = 0; for (int i = a; i <= b; i++) { if (sumDigits(i) * k == i) { count++; } } System.out.println(count); } } |