import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class row {
public static void main(String[] args) {
// long k = Long.parseLong(args[0]);
// long a = Long.parseLong(args[1]);
// long b = Long.parseLong(args[2]);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = null;
try {
s = in.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] parts = s.split(" ");
long k = Long.parseLong(parts[0]);
long a = Long.parseLong(parts[1]);
long b = Long.parseLong(parts[2]);
// System.err.println("k="+k);
// System.err.println("a="+a);
// System.err.println("b="+b);
// System.err.println("min=a/k="+(a/k));
int count = 0;
long min;
if (a % k != 0) {
min = (a / k) + 1;
} else {
min = a / k;
}
for(long i = min; i <= b / k; i++) {
long n=i*k;
int sum = 0;
// System.err.println("n_" + i + "="+n);
do {
int digit = (int) (n % 10);
// System.err.println(digit);
sum += digit * digit;
n=n/10;
} while(n > 0);
if (sum == i) {
// System.err.println("n_" + i + "="+n);
count++;
}
}
// System.err.println("count=" + count);
System.out.println(count);
System.exit(0);
}
}
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 52 53 54 55 56 57 58 59 60 61 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class row { public static void main(String[] args) { // long k = Long.parseLong(args[0]); // long a = Long.parseLong(args[1]); // long b = Long.parseLong(args[2]); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s = null; try { s = in.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String[] parts = s.split(" "); long k = Long.parseLong(parts[0]); long a = Long.parseLong(parts[1]); long b = Long.parseLong(parts[2]); // System.err.println("k="+k); // System.err.println("a="+a); // System.err.println("b="+b); // System.err.println("min=a/k="+(a/k)); int count = 0; long min; if (a % k != 0) { min = (a / k) + 1; } else { min = a / k; } for(long i = min; i <= b / k; i++) { long n=i*k; int sum = 0; // System.err.println("n_" + i + "="+n); do { int digit = (int) (n % 10); // System.err.println(digit); sum += digit * digit; n=n/10; } while(n > 0); if (sum == i) { // System.err.println("n_" + i + "="+n); count++; } } // System.err.println("count=" + count); System.out.println(count); System.exit(0); } } |
English