結果
| 問題 |
No.1039 Project Euler でやれ
|
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2020-04-24 23:50:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 3,267 bytes |
| コンパイル時間 | 1,979 ms |
| コンパイル使用メモリ | 183,080 KB |
| 実行使用メモリ | 15,488 KB |
| 最終ジャッジ日時 | 2024-11-08 02:59:37 |
| 合計ジャッジ時間 | 3,242 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end
template<unsigned mod=1000000007>struct mint {
unsigned val;
static unsigned get_mod(){return mod;}
unsigned inv() const{
int tmp,a=val,b=mod,x=1,y=0;
while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
if(x<0)x+=mod; return x;
}
mint():val(0){}
mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
mint operator+(const mint& x)const{return mint(*this)+=x;}
mint operator-(const mint& x)const{return mint(*this)-=x;}
mint operator*(const mint& x)const{return mint(*this)*=x;}
mint operator/(const mint& x)const{return mint(*this)/=x;}
bool operator==(const mint& x)const{return val==x.val;}
bool operator!=(const mint& x)const{return val!=x.val;}
}; using Mint=mint<>;
template<typename T>struct factorial {
vector<T> Fact,Finv,Inv;
factorial(int maxx){
Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; unsigned mod=Mint::get_mod();
rep(i,2,maxx){
Fact[i]=Fact[i-1]*i;
Inv[i]=Inv[mod%i]*(mod-mod/i);
Finv[i]=Finv[i-1]*Inv[i];
}
}
T fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
T inv(int n){return Inv[n];}
T nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
T nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
factorial<Mint> fact(1010000);
vector<vector<int>> part[21];
int main(){
part[0].push_back({0});
rep(i,0,20)for(auto v:part[i]){
int s=max(1,v.back());
rep(add,s,20-i){
auto w=v; w.push_back(add);
part[i+add].push_back(w);
}
}
int n; cin>>n;
Mint res=fact.fact(n);
vector<pair<int,int>> ps;
for(int p=2;p*p<=n;p++)if(n%p==0){
int cnt=0;
while(n%p==0)cnt++,n/=p;
ps.push_back({p,cnt});
}
if(n!=1)ps.push_back({n,1});
for(auto P:ps){
int p=P.first,cnt=P.second;
Mint mul;
for(auto& v:part[cnt]){
Mint add=1; int m=v.size();
vector<int> c(m),d(m);
rep(i,1,m)c[i]=d[i]=i;
rep(i,1,m)rep(j,1,m)if(v[i]==v[j]){
chmin(c[i],j); chmax(d[i],j);
}
rep(i,1,m)add*=(Mint(p).pow(d[i])-Mint(p).pow(i-1));
rep(i,1,m)add*=Mint(p).pow(v[i]*(m-d[i]-1));
rep(i,1,m)add*=Mint(p).pow((v[i]-1)*(m-c[i]));
mul+=add.inv();
} res*=mul;
} printf("%d\n",res.val);
return 0;
}
tko919