結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2016-09-12 21:53:33 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 876 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 32,384 KB |
実行使用メモリ | 6,016 KB |
最終ジャッジ日時 | 2024-11-17 04:06:03 |
合計ジャッジ時間 | 1,020 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 10 |
ソースコード
program mainimplicit noneinteger*8::x,N,total,iinteger*8,allocatable::a(:)integer::memo(0:100000000)data memo/100000001*0/,total/0/read *,x,Nallocate(a(N))read *,ado i=1,Ntotal = total + power(x,a(i),memo)end doprint '(i0)',totalcontainsrecursive function power(x,p,memo) result(y)integer*8::x,yinteger*8::pinteger,parameter::modulo=1000003integer::memo(0:100000000)if(memo(p).ne.0) theny = memo(p)else if(p.eq.0) theny = 1memo(p) = yelse if(p.eq.1) theny = xmemo(p) = yelseif(MOD(p,2).eq.0) theny = mod(power(x,p/2,memo)*power(x,p/2,memo),modulo)memo (p) = yelsey = mod(power(x,p/2+1,memo)*power(x,p/2,memo),modulo)memo (p) = yend ifend ifend function powerend program main