結果
問題 |
No.2032 Let's Write Multiples!!
|
ユーザー |
|
提出日時 | 2022-07-15 02:46:18 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,847 ms / 3,000 ms |
コード長 | 1,161 bytes |
コンパイル時間 | 2,090 ms |
コンパイル使用メモリ | 77,640 KB |
実行使用メモリ | 60,568 KB |
最終ジャッジ日時 | 2024-06-26 20:49:52 |
合計ジャッジ時間 | 39,049 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i < t; i++){ long l = sc.nextLong(); long r = sc.nextLong(); long k = sc.nextLong(); long c = sc.nextLong(); long ans = f(r, k, c) - f(l - 1, k, c); System.out.println(ans); } } public static long floorSum(long n, long m, long a, long b){ long ret = 0; if(a >= m){ ret += (n - 1) * n * (a/m)/2; a %= m; } if(b >= m){ ret += n * (b/m); b %= m; } long ym = (a * n + b) / m; long xm = (ym * m - b); if(ym == 0) return ret; ret += (n - (xm + a - 1)/a) * ym; ret += floorSum(ym, a, m, (a - xm % a) % a); return ret; } public static long f(long r, long k, long c){ long n = r / k; long ans = 0; long d = 1; for(int i = 0; i < 9; i++){ long x = c * d; long y = (c + 1) * d; d *= 10; ans += floorSum(n, d, k, d + k - x) - floorSum(n, d, k, d + k - y); } return ans; } }