結果
| 問題 | No.391 CODING WAR | 
| コンテスト | |
| ユーザー |  kuuso1 | 
| 提出日時 | 2016-07-08 23:57:30 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 218 ms / 2,000 ms | 
| コード長 | 2,231 bytes | 
| コンパイル時間 | 925 ms | 
| コンパイル使用メモリ | 108,416 KB | 
| 実行使用メモリ | 21,760 KB | 
| 最終ジャッジ日時 | 2024-10-13 07:38:26 | 
| 合計ジャッジ時間 | 3,519 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 16 | 
コンパイルメッセージ
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(val >= mod) val %= mod;
			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);
	}
	
}
            
            
            
        