結果
問題 | No.2649 [Cherry 6th Tune C] Anthem Flower |
ユーザー |
![]() |
提出日時 | 2024-02-23 23:44:15 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 285 ms / 2,000 ms |
コード長 | 891 bytes |
コンパイル時間 | 3,402 ms |
コンパイル使用メモリ | 245,396 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-29 09:11:36 |
合計ジャッジ時間 | 6,331 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; cin>>t; while(t--){ string n; ll m; cin>>n>>m; if(n.size()<10){ ll a=stoll(n); cout<<(a*(a+1)/2)%m<<'\n'; continue; } int k=n.size(); int d=0; if((n[k-1]-'0')%2==1) d=1; ll a,b,c=1,e=1; if(d==0) a=(n[k-1]-'0')/2,b=(n[k-1]-'0')+1; else a=(n[k-1]-'0'),b=(n[k-1]-'0'+1)/2; for(int i=k-2;i>=0;i--){ if(d==0){ if(i==k-2) c=c*5%m; else c=c*10%m; e=e*10%m; } else{ if(i==k-2) e=e*5%m; else e=e*10%m; c=c*10%m; } a=(a+(n[i]-'0')*c%m)%m; b=(b+(n[i]-'0')*e%m)%m; } cout<<a*b%m<<'\n'; } return 0; }