結果
問題 | No.2032 Let's Write Multiples!! |
ユーザー |
|
提出日時 | 2022-12-25 18:43:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 592 ms / 3,000 ms |
コード長 | 1,368 bytes |
コンパイル時間 | 1,573 ms |
コンパイル使用メモリ | 166,188 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-19 08:30:30 |
合計ジャッジ時間 | 9,516 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;long long floor_sum(long long n, long long m, long long a, long long b) {/*if(b < 0){ll up = (abs(b) + a - 1) / a;if(n < up)return 0;return floor_sum(n - up, m, a, b + up * a);}*/long long ans = 0;if (a >= m) {ans += (n - 1) * n * (a / m) / 2;a %= m;}if (b >= m) {ans += n * (b / m);b %= m;}long long y_max = (a * n + b) / m, x_max = (y_max * m - b);if (y_max == 0) return ans;ans += (n - (x_max + a - 1) / a) * y_max;ans += floor_sum(y_max, a, m, (a - x_max % a) % a);return ans;}//0 ~ nの範囲でc * 10 ^ e <= i * k < (c + 1) * 10 ^ e となる i の個数を求めるll f(ll n, ll k, ll c){ll d = 1, ans = 0;for(int i = 0; i < 9; i++){ll x = c * d;ll y = (c + 1) * d;d *= 10;ans += floor_sum(n, d, k, d - x) - floor_sum(n, d, k, d - y);//両方にdが加算されているため影響しない}return ans;}int main(){ios::sync_with_stdio(false);cin.tie(0);int T;cin >> T;while(T--){ll L, R, K, C, ans = 0, l, r, d = 1;cin >> L >> R >> K >> C;ans += f(R / K + 1, K, C);ans -= f((L - 1) / K + 1, K, C);cout << ans << '\n';}}