結果
| 問題 | 
                            No.1201 お菓子配り-4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             bachoppi
                         | 
                    
| 提出日時 | 2020-08-29 10:15:33 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,881 ms / 4,000 ms | 
| コード長 | 1,291 bytes | 
| コンパイル時間 | 1,497 ms | 
| コンパイル使用メモリ | 115,932 KB | 
| 最終ジャッジ日時 | 2025-01-13 20:04:32 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 36 | 
ソースコード
#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 tmp = 0;
  rep(i, n){
    rep(j, m){
      ll g = gcd(a[i], b[j]); ll made = b[j]/g - 1; ll ans = 0;
      //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;
      tmp+=ans; tmp%=mod;
    }
  }
  cout << tmp << endl;
}
            
            
            
        
            
bachoppi