結果
| 問題 | 
                            No.1201 お菓子配り-4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tute7627
                         | 
                    
| 提出日時 | 2020-08-28 22:18:06 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3,586 ms / 4,000 ms | 
| コード長 | 742 bytes | 
| コンパイル時間 | 2,849 ms | 
| コンパイル使用メモリ | 193,832 KB | 
| 最終ジャッジ日時 | 2025-01-13 18:07:39 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 36 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
int64_t f(int a, int b, int c, int n) {
    if (n < 0 || a == 0) return 0;
    if (a >= c || b >= c) 
        return (a / c) * (1LL * n * (n + 1) / 2) + 1LL * (b / c) * (n + 1) + f(a % c, b % c, c, n);
    int64_t m = (1LL * a * n + b) / c;
    return 1LL * n * m - f(c, c - b - 1, a, m - 1);
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  vector<int>a(n),b(m);
  const long long mod=1e9+7;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<m;i++)cin>>b[i];
  long long ret=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      long long add=f(a[i],0,b[j],b[j]);
      ret=(ret+add*2)%mod;
    }
  }
  cout<<ret<<endl;
}
            
            
            
        
            
tute7627