結果

問題 No.1039 Project Euler でやれ
ユーザー xllend3xllend3
提出日時 2020-04-24 23:12:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,495 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 174,664 KB
実行使用メモリ 11,620 KB
最終ジャッジ日時 2023-08-07 21:34:55
合計ジャッジ時間 2,642 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 7 ms
9,800 KB
testcase_02 AC 8 ms
9,556 KB
testcase_03 AC 13 ms
11,612 KB
testcase_04 AC 13 ms
11,620 KB
testcase_05 AC 8 ms
9,564 KB
testcase_06 AC 7 ms
9,556 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
5,112 KB
testcase_09 AC 6 ms
7,516 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
9,700 KB
testcase_12 AC 3 ms
4,664 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 6 ms
7,516 KB
testcase_15 AC 6 ms
9,532 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=1111111,M=111111;
int l,m,n,t,C;
ll ans;
vector<pii>V;
ll jc[N];
void calc(vector<pii>V){
	// for(auto i:V)printf("(%d %d)",i.X,i.Y);puts("");
	sort(V.begin(),V.end());
	ll res=1;
	rep(i,0,SZ(V)-1){
		int l=i,r=i;
		while(l>0&&V[l-1]==V[i])--l;while(r<SZ(V)-1&&V[r+1]==V[i])++r;
		int ct=l+1,dt=r+1,p=V[i].Y,et=V[i].X,m=SZ(V),di=i;
		m=0;rep(j,0,SZ(V)-1)if(V[j].Y==V[i].Y)++m;
		di=0;rep(j,0,i-1)if(V[j].Y==V[i].Y)++di;else --ct,--dt;
		// printf("%d %d\n",m,di);
		// printf("%d %d %d\n",i,powmod(p,dt)-powmod(p,di),powmod(p,et*(m-dt)+(et-1)*(m-ct+1)));
		res=res*((powmod(p,dt)-powmod(p,di))*powmod(p,et*(m-dt)+(et-1)*(m-ct+1))%mo)%mo;
	}
	// printf("%lld\n",res);
	res=jc[n]*powmod(res,mo-2)%mo;
	// printf("%lld\n",res);
	ans=(ans+res)%mo;
}
void dfs(int x,int y,int z){
	rep(i,y,x)if(x%i==0){
		int t=0;
		while(x%i==0){
			x/=i;++t;
			V.pb(mp(t,i));
			if(t>=z||i!=y)dfs(x,y,t);
			V.pop_back();
		}
		return;
	}
	calc(V);
}
int main(){
#ifdef LOCAL
	freopen("F.in","r",stdin);//freopen("F.out","w",stdout);
#endif
	scanf("%d",&n);
	jc[0]=1;rep(i,1,n)jc[i]=jc[i-1]*i%mo;
	dfs(n,2,0);
	cout<<ans<<endl;
	return 0;
}
0