結果

問題 No.391 CODING WAR
ユーザー suikameron1suikameron1
提出日時 2018-10-28 19:21:18
言語 C#(mono)
(mono 6.12.0.158)
結果
TLE  
実行時間 -
コード長 1,912 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 63,228 KB
実行使用メモリ 27,212 KB
最終ジャッジ日時 2023-08-12 08:07:57
合計ジャッジ時間 5,267 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
27,212 KB
testcase_01 AC 57 ms
20,716 KB
testcase_02 AC 57 ms
22,772 KB
testcase_03 AC 57 ms
20,660 KB
testcase_04 AC 57 ms
20,692 KB
testcase_05 AC 56 ms
20,736 KB
testcase_06 AC 57 ms
20,688 KB
testcase_07 AC 114 ms
22,800 KB
testcase_08 AC 71 ms
20,836 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
static long n = long.Parse(input[0]);
static long k = long.Parse(input[1]);
static long p = 1000000007;
static long answer = 0;
 
    static void Main()
    {
   
    if(k > n) answer = 0;
    else
    {
      for(long i = 0; i <= k-1; i++)
      {
        long memo = Comb(k, i, p) * DivideMod(k-i, n, p);
        if(i % 2 == 0)
        {
          answer += memo;
          answer %= p;
        }else
        {
          answer -= memo;
          answer %= p;
          if(answer < 0) answer += p;
        }
      }
    }
 
        Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
    }
 
  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
     
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }
 
  static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数
  {
    long answer = DivideMod(x, p-2, p);
    return answer;
  }
 
  static long DivideModFactorial(long x, long p)//戻り値はx!^-1(mod p), pは素数
  {
    long answer = 1;
    for(long i = x; i >= 2; i--)
    {
      answer *= DivideModReverse(i, p);
      answer %= p;
    }
    return answer;
  }
 
  static long Comb(long a, long b, long p)//戻り値は組み合わせC(a,b)のmod p
  {
    long answer = 1;
    for(long i = a; i > a-b; i--)
    {
      answer *= i;
      answer %= p;
    }
    answer *= DivideModFactorial(b, p);
    answer %= p;
    return answer;
  }
 
   
}
0