結果
| 問題 | No.377 背景パターン |
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2018-12-03 13:18:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,133 bytes |
| 記録 | |
| コンパイル時間 | 999 ms |
| コンパイル使用メモリ | 102,984 KB |
| 実行使用メモリ | 814,140 KB |
| 最終ジャッジ日時 | 2024-07-01 05:36:35 |
| 合計ジャッジ時間 | 3,885 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 8 MLE * 1 -- * 5 |
ソースコード
#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> ph, pw;
vector<ll> dh, dw;
vector<Pl> v;
int main()
{
ll h, w, k;
cin>>h>>w>>k;
/*ll h1=h, w1=w;
for(ll i=2; i*i<=h1; i++){
if(h1%i==0){
int e=0;
while(h1%i==0){
h1/=i;
}
ph.push_back(i);
}
}
if(h1>1) ph.push_back(h1);*/
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=2; i*i<=w1; i++){
if(w1%i==0){
int e=0;
while(w1%i==0){
w1/=i;
}
pw.push_back(i);
}
}
if(w1>1) pw.push_back(w1);*/
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 c[100000]={};
for(int i=0; i<dh.size(); i++){
for(int j=0; j<dw.size(); j++){
ll t=dw[j]/gcd(h/dh[i], dw[j]);
for(ll l=0; l<dw[j]; l+=t){
//if(h/dh[i]*l%dw[j]==0){
v.push_back(Pl(P(dh[i], dw[j]), l));
//}
}
}
}
ll ans=k;
int m=v.size();
c[0]=k;
for(int i=1; i<m; i++){
ll a=v[i].first.first, d=v[i].first.second, b=v[i].second;
//cout<<a<<" "<<d<<" "<<b<<endl;
ll s=a*d;
c[i]=powmod(k, s);
for(int j=0; j<i; j++){
ll a2=v[j].first.first, d2=v[j].first.second, b2=v[j].second;
if(a%a2==0 && d%d2==0 && a/a2*b2%d2==b%d2){
c[i]+=(MOD-c[j]);
c[i]%=MOD;
}
}
ans+=(c[i]*inv(s%MOD)%MOD);
ans%=MOD;
}
cout<<ans<<endl;
return 0;
}
chocorusk