結果
問題 |
No.1092 modular arithmetic
|
ユーザー |
![]() |
提出日時 | 2020-07-27 20:45:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 843 bytes |
コンパイル時間 | 1,629 ms |
コンパイル使用メモリ | 165,856 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 20:13:52 |
合計ジャッジ時間 | 4,584 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 23 WA * 9 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for(int i= 0; i < (n); i++) using ll= long long int; using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll mod= 1e9 + 7; ll RepeatSquaring(ll N, ll P, ll M){ if(P==0) return 1; if(P%2==0){ ll t = RepeatSquaring(N, P/2, M); return t*t % M; } return N * RepeatSquaring(N, P-1, M)%M; } int main(){ ll p,n; cin >> p >> n; ll a[n]; rep(i,n)cin >> a[i]; ll ans=a[0]; for(int i=1;i<n;i++){ char g; cin >> g; if(g=='+'){ans+=a[i];} else if(g=='-'){ans-=a[i];} else if(g=='*'){ans*=a[i];} else if(g=='/'){ans*=RepeatSquaring(a[i],p-2,p);} ans%=p; } cout << ans << endl; }