結果

問題 No.377 背景パターン
ユーザー chocoruskchocorusk
提出日時 2018-12-03 14:09:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 570 ms / 5,000 ms
コード長 1,646 bytes
コンパイル時間 2,665 ms
コンパイル使用メモリ 97,412 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 21:08:20
合計ジャッジ時間 4,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 562 ms
4,380 KB
testcase_17 AC 570 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> Pl;
const ll MOD=1e9+7;
ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
vector<ll> dh, dw;
int main()
{
	ll h, w, k;
	cin>>h>>w>>k;
	for(ll i=1; i*i<=h; i++){
		if(h%i==0){
			dh.push_back(i);
			if(i*i<h) dh.push_back(h/i);
		}
	}
	sort(dh.begin(), dh.end());
	for(ll i=1; i*i<=w; i++){
		if(w%i==0){
			dw.push_back(i);
			if(i*i<w) dw.push_back(w/i);
		}
	}
	sort(dw.begin(), dw.end());
  ll ans=0;
  ll ct1[1400], ct2[1400];;
  ct1[dh.size()-1]=1;
  for(int i=dh.size()-1; i>=0; i--){
    ct1[i]=h/dh[i];
    for(int j=i+1; j<dh.size(); j++){
      if(dh[j]%dh[i]==0) ct1[i]-=ct1[j];
    }
  }
  ct2[dw.size()-1]=1;
  for(int i=dw.size()-1; i>=0; i--){
    ct2[i]=w/dw[i];
    for(int j=i+1; j<dw.size(); j++){
      if(dw[j]%dw[i]==0) ct2[i]-=ct2[j];
    }
  }
  for(int i=0; i<dh.size(); i++){
    for(int j=0; j<dw.size(); j++){
      ll d=h/dh[i]/gcd(h/dh[i], w/dw[j])*w/dw[j];
      ans+=(ct1[i]*ct2[j]%MOD*powmod(k, h*w/d)%MOD);
      ans%=MOD;
    }
  }
  cout<<ans*inv(h*w%MOD)%MOD<<endl;
  return 0;
}
0