結果

問題 No.1039 Project Euler でやれ
ユーザー chocoruskchocorusk
提出日時 2020-04-24 21:59:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 2,738 bytes
コンパイル時間 1,393 ms
コンパイル使用メモリ 131,680 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 21:33:52
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
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);
}
ll f[200020], invf[200020];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int m; cin>>m;
  int m1=m;
    vector<P> fac;
    for(int i=2; i*i<=m; i++){
        if(m%i==0){
            int e=0;
            while(m%i==0){
                m/=i;
                e++;
            }
            fac.push_back({i, e});
        }
    }
    if(m>1) fac.push_back({m, 1});
    ll ans=1;
    for(auto q:fac){
        ll ans1=0;
        int e=q.second, p=q.first;
        auto dfs=[&](auto dfs, int e1, vector<P> &v){
            if(e1==0){
                ll s=1;
                for(int i=0; i<v.size(); i++){
                    int k=v[i].second, n=v[i].first;
                  //cout<<n<<" "<<k<<endl;
                    s*=powmod(p, (ll)(n-1)*k*k);
                    s%=MOD;
                    for(int j=0; j<k; j++){
                        (s*=(powmod(p, k)-powmod(p, j)+MOD))%=MOD;
                    }
                    for(int j=0; j<v.size(); j++){
                        if(i==j) continue;
                        (s*=powmod(p, (ll)min(v[j].first, n)*v[j].second*k))%=MOD;
                    }
                }
              //cout<<endl;
                (ans1+=inv(s))%=MOD;
                return;
            }
            for(int k=1; k<=e1 && (v.empty() || k<v.back().first); k++){
                for(int j=1; j*k<=e1; j++){
                    if(k==1 && j<e1) continue;
                    v.push_back({k, j});
                    dfs(dfs, e1-j*k, v);
                    v.pop_back();
                }
            }
        };
        vector<P> v;
        dfs(dfs, e, v);
        (ans*=ans1)%=MOD;
    }
    for(int i=1; i<=m1; i++) (ans*=i)%=MOD;
    cout<<ans<<endl;
    return 0;
}
0