結果
問題 |
No.2649 [Cherry 6th Tune C] Anthem Flower
|
ユーザー |
|
提出日時 | 2024-02-26 20:21:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 997 bytes |
コンパイル時間 | 2,971 ms |
コンパイル使用メモリ | 254,360 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-09-29 11:43:49 |
合計ジャッジ時間 | 6,715 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { string N; ll M; cin >> N >> M; auto inc = [&](string s) { ranges::reverse(s); s += '0'; for(auto &i : s) { if(i != '9') { i++; break; } else { i = '0'; } } ranges::reverse(s); return s; }; auto div = [&](string s) { ll n = s.size(); vector<ll> v; for(auto &i : s) { v.emplace_back(i - '0'); } string r = ""; for(ll i = 0; i < n; i++) { r += char(v[i] / 2 + '0'); if(v[i] & 1) { v[i + 1] += 10; } } return r; }; auto rem = [&](string s) { ll r = 0; for(auto &i : s) { r *= 10; r += (i - '0'); r %= M; } return r; }; if((N.back() - '0') & 1) { cout << rem(N) * rem(div(inc(N))) % M << "\n"; } else { cout << rem(inc(N)) * rem(div(N)) % M << "\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(0); ll t; cin >> t; while(t--) { solve(); } }