Submission #73060536
Source Code Expand
/*
* ------------------------------------------------------------
* Author: Karan Singh Chauhan
* © 2025 Karan Singh Chauhan. All rights reserved.
* ------------------------------------------------------------
* Competitive Programming Template (Java 21)
* ------------------------------------------------------------
* Features:
* -> Ultra-fast I/O (FastReader + PrintWriter)
* -> Common Math Utilities (GCD, LCM, Modular Arithmetic)
* -> Pair record + Custom sorting helpers
* -> Debug mode (auto-disabled for online judge)
* -> Auto file input/output (input.txt → output.txt)
* ------------------------------------------------------------
*/
import java.io.*;
import java.util.*;
public class Main {
static final long MOD = 1_000_000_007L;
static final int INF = (int) 1e9;
static final long LINF = (long) 1e18;
static FastReader sc;
static PrintWriter out;
static boolean DEBUG = System.getProperty("ONLINE_JUDGE") == null;
public static void main(String[] args) throws Exception {
if (DEBUG) {
try {
sc = new FastReader(new FileInputStream("input.txt"));
out = new PrintWriter(new FileOutputStream("output.txt"));
} catch (FileNotFoundException e) {
System.err.println(" input.txt not found! Falling back to standard input/output.");
sc = new FastReader(System.in);
out = new PrintWriter(new BufferedOutputStream(System.out));
}
} else {
sc = new FastReader(System.in);
out = new PrintWriter(new BufferedOutputStream(System.out));
}
int t = 1;
// Uncomment below for multiple test cases
while (t-- > 0) solve();
out.flush();
out.close();
}
static void solve() {
// Write your code here ↓↓↓
int n = in();
int k = in();
int count = 0;
for(int i = 1; i <= n; i++){
if(k == digit(i)){
count++;
}
}
System.out.println(count);
}
static int digit(int n){
int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// ------------------------------------------------------------
// Smaller Reader For Fast Input
// ------------------------------------------------------------
static int in(){
return sc.nextInt();
}
static long ll(){
return sc.nextLong();
}
static String ss(){
return sc.next();
}
static int[] ia(int n){
return sc.readIntArray(n);
}
static long[] la(int n){
return sc.readLongArray(n);
}
// ------------------------------------------------------------
// MATH UTILITIES
// ------------------------------------------------------------
static long gcd(long a, long b) {
while (b != 0) { long tmp = a % b; a = b; b = tmp; } return a;
}
static long lcm(long a, long b) { return a / gcd(a, b) * b; }
static long modAdd(long a, long b) { long res = (a + b) % MOD; return res < 0 ? res + MOD : res; }
static long modSub(long a, long b) { long res = (a - b) % MOD; return res < 0 ? res + MOD : res; }
static long modMul(long a, long b) { return (a % MOD) * (b % MOD) % MOD; }
static long modPow(long base, long exp) { long res = 1; base %= MOD; while (exp > 0) { if ((exp & 1) == 1) res = (res * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return res; }
static long modInverse(long a) { return modPow(a, MOD - 2); }
// ------------------------------------------------------------
// HELPER RECORDS / STRUCTURES (Java 21)
// ------------------------------------------------------------
record Pair(int x, int y) implements Comparable<Pair> {
@Override
public int compareTo(Pair o) {
int cmp = Integer.compare(x, o.x);
return cmp != 0 ? cmp : Integer.compare(y, o.y);
}
@Override
public String toString() { return "(" + x + ", " + y + ")"; }
}
// ------------------------------------------------------------
// ⚡ FAST INPUT READER
// ------------------------------------------------------------
static class FastReader {
private final byte[] buffer = new byte[1 << 16];
private int ptr = 0, len = 0;
private final InputStream in;
FastReader(InputStream stream) { in = stream; }
private int readByte() {
if (ptr >= len) {
ptr = 0;
try { len = in.read(buffer); if (len <= 0) return -1; } catch (IOException e) { return -1; }
}
return buffer[ptr++];
}
String next() {
int c; StringBuilder sb = new StringBuilder();
do { c = readByte(); } while (c <= ' ');
while (c > ' ') { sb.append((char) c); c = readByte(); }
return sb.toString();
}
int nextInt() {
int c, sign = 1, val = 0;
do { c = readByte(); } while (c <= ' ');
if (c == '-') { sign = -1; c = readByte(); }
while (c > ' ') { val = val * 10 + (c - '0'); c = readByte(); }
return val * sign;
}
long nextLong() {
int c, sign = 1; long val = 0;
do { c = readByte(); } while (c <= ' ');
if (c == '-') { sign = -1; c = readByte(); }
while (c > ' ') { val = val * 10 + (c - '0'); c = readByte(); }
return val * sign;
}
double nextDouble() { return Double.parseDouble(next()); }
int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; }
long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; }
}
// ------------------------------------------------------------
// DEBUG UTILITIES
// ------------------------------------------------------------
static void debug(Object... o) { if (DEBUG) out.println(Arrays.deepToString(o)); }
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Digit Sum |
| User | KaranChauhan |
| Language | Java24 (OpenJDK 24.0.2) |
| Score | 200 |
| Code Size | 6371 Byte |
| Status | AC |
| Exec Time | 48 ms |
| Memory | 38532 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| random_01.txt | AC | 48 ms | 38364 KiB |
| random_02.txt | AC | 42 ms | 38316 KiB |
| random_03.txt | AC | 38 ms | 38048 KiB |
| random_04.txt | AC | 43 ms | 38352 KiB |
| random_05.txt | AC | 40 ms | 38264 KiB |
| random_06.txt | AC | 44 ms | 38532 KiB |
| random_07.txt | AC | 41 ms | 38400 KiB |
| random_08.txt | AC | 43 ms | 38324 KiB |
| random_09.txt | AC | 43 ms | 38412 KiB |
| sample_01.txt | AC | 39 ms | 38040 KiB |
| sample_02.txt | AC | 39 ms | 37976 KiB |
| sample_03.txt | AC | 43 ms | 38064 KiB |