結果
問題 | No.278 連続する整数の和(2) |
ユーザー |
![]() |
提出日時 | 2016-08-31 23:13:52 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,008 bytes |
コンパイル時間 | 1,738 ms |
コンパイル使用メモリ | 32,640 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 13:39:39 |
合計ジャッジ時間 | 2,667 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 3 |
ソースコード
program mainimplicit noneinteger*8::C,N,i,j,ABGCDread *,Nif(MOD(N,2).eq.0) thenABGCD = gcd(2*N,1+N)N = N/2elseABGCD = gcd(N,(1+N)/2)end ifC = 1call sub(ABGCD,C)call sub(N,C)print '(i0)',Ccontainssubroutine sub(N,c)integer*8,intent(inout)::N,Cinteger*8::i,j,SQRTNinteger*1,allocatable::insuu(:)SQRTN =INT(SQRT(DBLE(N)))allocate(insuu(SQRTN))insuu = 0do i=2,SQRTNif(insuu(i).eq.1) continuedo j=i+i,SQRTN,iinsuu(j) = 1end doif(MOD(N,i).eq.0) thendoC = (i+1)*CN = N/iif(MOD(N,i).ne.0) exitend doend ifif(N.eq.1) exitend doif(N.ne.1) C = C*(1+N)deallocate(insuu)end subroutine subrecursive function gcd(a,b) result(c)implicit noneinteger*8::a,b,cif(b.eq.0) thenc = aelsec = gcd(b,MOD(a,b))end ifend function gcdend program main