結果
問題 |
No.391 CODING WAR
|
ユーザー |
![]() |
提出日時 | 2018-04-13 02:51:50 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 641 bytes |
コンパイル時間 | 859 ms |
コンパイル使用メモリ | 21,504 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 21:36:59 |
合計ジャッジ時間 | 1,401 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
コンパイルメッセージ
main.c: In function ‘run’: main.c:23:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%lld%lld",&n,&m); | ^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h> typedef long long int int64; int64 modPow(int r,int64 n,int mod){ int64 s=r; int64 t=1; while(n>0){ if(n&0x01) t=t*s%mod; s=s*s%mod; n>>=1; } return t; } int64 inv(int n,int p){ return modPow(n,p-2,p); } void run(void){ const int mod=1000000007; int64 n,m; scanf("%lld%lld",&n,&m); if(n<m){ printf("0\n"); return; } int64 ans=modPow(m,n,mod); int64 comb=1; int d=-1; int k; for(k=1;k<m;k++){ comb=comb*(m-k+1)%mod*inv(k,mod)%mod; ans=(ans+d*modPow(m-k,n,mod)*comb%mod+mod)%mod; d*=-1; } printf("%lld\n",ans); } int main(void){ run(); return 0; }