結果
| 問題 |
No.1201 お菓子配り-4
|
| コンテスト | |
| ユーザー |
bachoppi
|
| 提出日時 | 2020-08-29 10:01:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,254 bytes |
| コンパイル時間 | 2,948 ms |
| コンパイル使用メモリ | 115,800 KB |
| 最終ジャッジ日時 | 2025-01-13 20:03:30 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 35 |
ソースコード
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main(){
int n, m; cin >> n >> m;
ll a[n], b[m];
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
ll ans = 0;
rep(i, n){
rep(j, m){
ll g = gcd(a[i], b[j]); ll made = b[j]/g - 1;
//cout << made << endl;
ans+=a[i]*b[j]%mod*(b[j]+1)%mod;
//cout << ans << endl;
ans-=g*g%mod*made%mod*(made+1)%mod;
//cout << ans << endl;
if(ans<0) ans+=mod; ans%=mod;
ans*=modinv(b[j], mod); ans%=mod;
}
}
cout << ans << endl;
}
bachoppi