結果
問題 |
No.16 累乗の加算
|
ユーザー |
![]() |
提出日時 | 2017-07-08 19:01:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 429 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 24,704 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 05:23:46 |
合計ジャッジ時間 | 735 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
コンパイルメッセージ
main.cpp:4:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 4 | main(){ | ^~~~ main.cpp: In function ‘int main()’: main.cpp:13:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=] 13 | printf("%d\n",sum%M); | ~^ ~~~~~ | | | | int long long int | %lld main.cpp:6:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d%d",&X,&N); | ~~~~~^~~~~~~~~~~~~~ main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d",&a); | ~~~~~^~~~~~~~~
ソースコード
#include<stdio.h> int pow(long long x,int n); int M = 1000003; main(){ int X,N; scanf("%d%d",&X,&N); long long sum = 0; for(int i = 0;i < N;i++){ int a; scanf("%d",&a); sum += pow(X,a); } printf("%d\n",sum%M); } //x^nを求める int pow(long long x,int n){ if(n == 0){return 1;} int ans = pow(x*x%M,n/2); if(n%2 == 1){ ans = ans*x % M; } return ans; }