結果

問題 No.16 累乗の加算
ユーザー akakimidori
提出日時 2016-12-08 01:11:34
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 447 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 22,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 05:18:38
合計ジャッジ時間 888 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:16:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |   scanf("%d%d",&x,&n);
      |   ^~~~~~~~~~~~~~~~~~~
main.c:21:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     scanf("%lld",&a);
      |     ^~~~~~~~~~~~~~~~

ソースコード

diff #

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

typedef long long int ln;

ln calcPow(int r,ln n,int mod){
  if(n==0) return 1;

  ln t=calcPow(r,n/2,mod);
  return (((t*t)%mod)*(n%2==0?1:r))%mod;
}

void run(void){
  const int m=1000003;
  int x,n;
  scanf("%d%d",&x,&n);

  ln ans=0;
  while(n>0){
    ln a;
    scanf("%lld",&a);
    ans+=calcPow(x,a,m);;
    n--;
  }
  ans%=m;
  printf("%lld\n",ans);
  return;
}

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