結果

問題 No.1201 お菓子配り-4
ユーザー motmot
提出日時 2020-09-01 16:47:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,319 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 84,080 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-29 22:25:41
合計ジャッジ時間 30,088 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 OLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 OLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll gcd(ll a, ll b) {
  ll v0=a, v1=b, v2=v0%v1;
  while(v2>0) {
    v0 = v1;
    v1 = v2;
    v2 = v0%v1;
  }
  return v1;
}

int main() {
  int N, M;
  cin>>N>>M;
  ll A[N], B[M];
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<M;++i) cin>>B[i];
  ll ans = 0;
  ll a, b;
  ll tmp, t, num, tmpsum;
  for(int i=0;i<N;++i) {
    for(int j=0;j<M;++j) {
      a = A[i];
      b = B[j];
      ans += b*(b+1)/2%mod*(a/b%mod)%mod;
      ans %= mod;
      a %= b;
      if(a==0) continue;
      tmp = gcd(a, b);
      t = b/tmp;
      tmp = t*a/b%mod;
      num = (t-1)/tmp;
      tmpsum = (tmp-1)*tmp/2%mod*num%mod;
      tmpsum += tmp;
      tmpsum %= mod;
      ans += b/t*tmpsum%mod;
      ans %= mod;
      cout<<tmp<<endl;
      ans += (b/t-1)*(b/t)/2%mod*tmp%mod*t%mod;
      ans %= mod;
    }
  }
  cout<<2*ans%mod<<endl;
}

0