結果
問題 |
No.391 CODING WAR
|
ユーザー |
![]() |
提出日時 | 2016-07-08 23:56:36 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,201 bytes |
コンパイル時間 | 2,785 ms |
コンパイル使用メモリ | 108,544 KB |
実行使用メモリ | 21,760 KB |
最終ジャッジ日時 | 2024-10-13 07:37:31 |
合計ジャッジ時間 | 5,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 3 WA * 13 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ modComb.Init((int)2e6); long ans = 0; long mod = (long)1e9+7; int sig = 1; for(long i=M;i>=1;i--){ long val = modComb.PowMod(i,N); val *= modComb.nCrMod(M,i); if(sig == 1) ans += val; if(sig == -1) ans += (mod - val); if(ans >= mod) ans -= mod; sig *= -1; } Console.WriteLine(ans); } long N,M; public Sol(){ var d = rla(); N = d[0]; M = d[1]; } static String rs(){return Console.ReadLine();} static int ri(){return int.Parse(Console.ReadLine());} static long rl(){return long.Parse(Console.ReadLine());} static double rd(){return double.Parse(Console.ReadLine());} static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);} static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));} static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));} static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));} } class modComb{ public static long mod=(long)(1e9+7); public static long nCrMod(long n,long r){ if(n<r)return 0; if(n<0)return 0; if(r<0)return 0; if(n==0||r==n||r==0)return 1; long a=FactorialMod(n); long b=InvMod(FactorialMod(r)); long c=InvMod(FactorialMod(n-r)); long ans=(((a*b)%mod)*c)%mod; return ans; } public static long[] FM; public static void Init(int sz){ FM = new long[sz]; } public static long FactorialMod(long n){ if(FM[(int)n]!=0)return FM[(int)n]; if(n<2)return FM[(int)n]=1; long ret=n*FactorialMod(n-1); ret%=mod; return FM[(int)n]=ret; } public static long PowMod(long n,long k){ if(k==0)return 1; if(n==0)return 0; long ret=1; long x=n; while(k>0){ if((k&1)==1){ret*=x;ret%=mod;} x*=x;x%=mod; k>>=1; } return ret; } public static long InvMod(long n){ //(mod-2)乗を返す // modが素数の時だけ!!!! return PowMod(n,mod-2); } }