結果

問題 No.377 背景パターン
ユーザー chocoruskchocorusk
提出日時 2018-12-03 13:18:40
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 2,133 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 102,852 KB
実行使用メモリ 813,840 KB
最終ジャッジ日時 2023-09-13 21:07:59
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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> 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;
}
0