結果
問題 | No.1259 スイッチ |
ユーザー | kotatsugame |
提出日時 | 2020-10-24 00:39:41 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 2,784 bytes |
コンパイル時間 | 564 ms |
コンパイル使用メモリ | 66,328 KB |
実行使用メモリ | 15,908 KB |
最終ジャッジ日時 | 2024-07-21 14:27:52 |
合計ジャッジ時間 | 4,069 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
15,712 KB |
testcase_01 | AC | 20 ms
15,740 KB |
testcase_02 | AC | 20 ms
15,660 KB |
testcase_03 | AC | 20 ms
15,704 KB |
testcase_04 | AC | 20 ms
15,716 KB |
testcase_05 | AC | 20 ms
15,732 KB |
testcase_06 | AC | 20 ms
15,752 KB |
testcase_07 | AC | 20 ms
15,772 KB |
testcase_08 | AC | 19 ms
15,616 KB |
testcase_09 | AC | 20 ms
15,712 KB |
testcase_10 | AC | 30 ms
15,776 KB |
testcase_11 | AC | 36 ms
15,744 KB |
testcase_12 | AC | 29 ms
15,744 KB |
testcase_13 | AC | 25 ms
15,688 KB |
testcase_14 | AC | 28 ms
15,736 KB |
testcase_15 | AC | 25 ms
15,708 KB |
testcase_16 | AC | 33 ms
15,712 KB |
testcase_17 | AC | 27 ms
15,748 KB |
testcase_18 | AC | 34 ms
15,884 KB |
testcase_19 | AC | 35 ms
15,716 KB |
testcase_20 | AC | 31 ms
15,728 KB |
testcase_21 | AC | 36 ms
15,752 KB |
testcase_22 | AC | 24 ms
15,736 KB |
testcase_23 | AC | 35 ms
15,588 KB |
testcase_24 | AC | 31 ms
15,712 KB |
testcase_25 | AC | 30 ms
15,768 KB |
testcase_26 | AC | 37 ms
15,908 KB |
testcase_27 | AC | 33 ms
15,756 KB |
testcase_28 | AC | 31 ms
15,812 KB |
testcase_29 | AC | 33 ms
15,756 KB |
testcase_30 | AC | 25 ms
15,728 KB |
testcase_31 | AC | 27 ms
15,620 KB |
testcase_32 | AC | 23 ms
15,816 KB |
testcase_33 | AC | 30 ms
15,720 KB |
testcase_34 | AC | 26 ms
15,832 KB |
testcase_35 | AC | 27 ms
15,824 KB |
testcase_36 | AC | 27 ms
15,692 KB |
testcase_37 | AC | 26 ms
15,568 KB |
testcase_38 | AC | 26 ms
15,784 KB |
testcase_39 | AC | 29 ms
15,720 KB |
testcase_40 | AC | 30 ms
15,568 KB |
testcase_41 | AC | 27 ms
15,708 KB |
testcase_42 | AC | 29 ms
15,672 KB |
testcase_43 | AC | 26 ms
15,812 KB |
testcase_44 | AC | 29 ms
15,896 KB |
testcase_45 | AC | 30 ms
15,680 KB |
testcase_46 | AC | 25 ms
15,700 KB |
testcase_47 | AC | 30 ms
15,784 KB |
testcase_48 | AC | 24 ms
15,688 KB |
testcase_49 | AC | 30 ms
15,744 KB |
testcase_50 | AC | 29 ms
15,740 KB |
testcase_51 | AC | 25 ms
15,712 KB |
testcase_52 | AC | 35 ms
15,756 KB |
testcase_53 | AC | 27 ms
15,804 KB |
testcase_54 | AC | 36 ms
15,680 KB |
testcase_55 | AC | 24 ms
15,568 KB |
testcase_56 | AC | 27 ms
15,800 KB |
testcase_57 | AC | 34 ms
15,584 KB |
testcase_58 | AC | 30 ms
15,700 KB |
testcase_59 | AC | 32 ms
15,788 KB |
testcase_60 | AC | 37 ms
15,752 KB |
コンパイルメッセージ
a.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp" #include<iostream> using namespace std; #line 3 "/home/kotatsugame/library/math/modint.cpp" #include<utility> template<int m> struct modint{ unsigned int x; constexpr modint()noexcept:x(){} template<typename T> constexpr modint(T x_)noexcept:x((x_%=m)<0?x_+m:x_){} constexpr unsigned int val()const noexcept{return x;} constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;} constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;} constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;} constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;} constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;} constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;} constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;} constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();} constexpr modint operator+()const noexcept{return*this;} constexpr modint operator-()const noexcept{return modint()-*this;} constexpr modint pow(long long n)const noexcept { if(n<0)return pow(-n).inv(); modint x=*this,r=1; for(;n;x*=x,n>>=1)if(n&1)r*=x; return r; } constexpr modint inv()const noexcept { int s=x,t=m,x=1,u=0; while(t) { int k=s/t; s-=k*t; swap(s,t); x-=k*u; swap(x,u); } return modint(x); } friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;} friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;} friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;} friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;} friend constexpr bool operator==(const modint&a,const modint&b){return a.x==b.x;} friend constexpr bool operator!=(const modint&a,const modint&b){return a.x!=b.x;} friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;} friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;} }; #line 4 "a.cpp" using mint=modint<(int)1e9+7>; int N,M; long K; mint pN[1<<20]; mint fac[1<<20],inv[1<<20]; mint P(int a,int b){return fac[a]*inv[a-b];} main() { cin>>N>>K>>M; pN[0]=1; for(int i=1;i<1<<20;i++)pN[i]=pN[i-1]*N; fac[0]=1; for(int i=1;i<1<<20;i++)fac[i]=fac[i-1]*i; inv[(1<<20)-1]=1/fac[(1<<20)-1]; for(int i=(1<<20)-1;i--;)inv[i]=inv[i+1]*(i+1); if(M==1) { mint ans=0; for(int i=1;i<=N;i++)if(K%i==0) { ans+=P(N-1,i-1)*pN[N-i]; } cout<<ans<<endl; } else { mint ans=0; for(int k=2;k<=N;k++) { ans+=P(N-2,k-2)*pN[N-k]*(k-1); } for(int i=2;i<=N;i++)if(K%i!=0) { ans+=P(N-2,i-2)*pN[N-i]; } cout<<ans<<endl; } }