import java.util.Scanner;
class row {
public static void main(String[] args) {
try (Scanner InputScanner = new Scanner(System.in)) {
String[] Input = InputScanner.nextLine().split(" ");
long K = Long.parseLong(Input[0]);
long A = Long.parseLong(Input[1]);
long B = Long.parseLong(Input[2]);
int MatchesCount = 0;
for(long CurrentInteger = A; CurrentInteger <= B; CurrentInteger++) {
if (K * GetDigitSquareSum(CurrentInteger) == CurrentInteger) {
MatchesCount = MatchesCount + 1;
}
}
System.out.println(MatchesCount);
}
}
private static int GetDigitSquareSum(long InputInteger) {
int DigitSquareSum = 0;
for (long CurrentInteger = InputInteger; CurrentInteger != 0; CurrentInteger /= 10) {
int Digit = (int) (CurrentInteger % 10);
DigitSquareSum = DigitSquareSum + (Digit * Digit);
}
return DigitSquareSum;
}
}
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 | import java.util.Scanner; class row { public static void main(String[] args) { try (Scanner InputScanner = new Scanner(System.in)) { String[] Input = InputScanner.nextLine().split(" "); long K = Long.parseLong(Input[0]); long A = Long.parseLong(Input[1]); long B = Long.parseLong(Input[2]); int MatchesCount = 0; for(long CurrentInteger = A; CurrentInteger <= B; CurrentInteger++) { if (K * GetDigitSquareSum(CurrentInteger) == CurrentInteger) { MatchesCount = MatchesCount + 1; } } System.out.println(MatchesCount); } } private static int GetDigitSquareSum(long InputInteger) { int DigitSquareSum = 0; for (long CurrentInteger = InputInteger; CurrentInteger != 0; CurrentInteger /= 10) { int Digit = (int) (CurrentInteger % 10); DigitSquareSum = DigitSquareSum + (Digit * Digit); } return DigitSquareSum; } } |
English