結果

問題 No.573 a^2[i] = a[i]
ユーザー akakimidori
提出日時 2018-07-11 10:52:46
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 23,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-16 06:29:28
合計ジャッジ時間 1,641 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:24:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int modPow(int r,int n,int mod){
  int t=1;
  int s=r;
  while(n>0){
    if(n&0x01) t=(int64)t*s%mod;
    s=(int64)s*s%mod;
    n>>=1;
  }
  return t;
}

void run(void){
  int n;
  scanf("%d",&n);
  const int mod=1000000007;
  int way=0;
  int comb=n;
  int r;
  for(r=1;r<=n;r++){
    way=(way+(int64)comb*modPow(r,n-r,mod))%mod;
    comb=(int64)comb*(n-r)%mod*modPow(r+1,mod-2,mod)%mod;
  }
  printf("%d\n",way);
}

int main(void){
  run();
  return 0;
}
0