結果
| 問題 |
No.377 背景パターン
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-05-29 17:56:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,067 ms / 5,000 ms |
| コード長 | 2,257 bytes |
| コンパイル時間 | 2,304 ms |
| コンパイル使用メモリ | 202,988 KB |
| 最終ジャッジ日時 | 2025-01-07 04:10:06 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T,T MOD = 1000000007>
struct Mint{
T v;
Mint():v(0){}
Mint(signed v):v(v){}
Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}
Mint pow(long long k){
Mint res(1),tmp(v);
while(k){
if(k&1) res*=tmp;
tmp*=tmp;
k>>=1;
}
return res;
}
static Mint add_identity(){return Mint(0);}
static Mint mul_identity(){return Mint(1);}
Mint inv(){return pow(MOD-2);}
Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
Mint& operator/=(Mint a){return (*this)*=a.inv();}
Mint operator+(Mint a) const{return Mint(v)+=a;};
Mint operator-(Mint a) const{return Mint(v)-=a;};
Mint operator*(Mint a) const{return Mint(v)*=a;};
Mint operator/(Mint a) const{return Mint(v)/=a;};
Mint operator-() const{return v?Mint(MOD-v):Mint(v);}
bool operator==(const Mint a)const{return v==a.v;}
bool operator!=(const Mint a)const{return v!=a.v;}
bool operator <(const Mint a)const{return v <a.v;}
};
Int phi(Int n){
Int res=n;
for(Int i=2;i*i<=n;i++){
if(n%i==0){
res=res/i*(i-1);
for(;n%i==0;n/=i);
}
}
if(n!=1) res=res/n*(n-1);
return res;
}
template<typename T>
vector<T> compress(vector<T> v){
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
return v;
}
struct FastIO{
FastIO(){
cin.tie(0);
ios::sync_with_stdio(0);
}
}fastio_beet;
//INSERT ABOVE HERE
signed main(){
Int h,w,k;
cin>>h>>w>>k;
vector<Int> hs,ws;
for(Int i=1;i*i<=h;i++){
if(h%i) continue;
hs.emplace_back(i);
hs.emplace_back(h/i);
}
for(Int i=1;i*i<=w;i++){
if(w%i) continue;
ws.emplace_back(i);
ws.emplace_back(w/i);
}
hs=compress(hs);
ws=compress(ws);
using M = Mint<Int>;
M ans{0};
for(Int y:hs)
for(Int x:ws)
ans+=M(phi(y))*M(phi(x))*M(k).pow((h/y)*(w/x)*__gcd(y,x));
ans/=M(h*w);
cout<<ans.v<<endl;
return 0;
}
beet