結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2016-07-24 02:36:52 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,192 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 34,944 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-01 15:47:22 |
合計ジャッジ時間 | 806 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
subroutine get_prime(PrimeList, N) implicit none integer::i,j,N integer,parameter::prime=1,nonprime=0,unkown=-1 integer,allocatable::isPrime(:), PrimeList(:) integer,allocatable::numlist(:) allocate(isPrime(N)) isPrime=prime isPrime(1)=nonprime isPrime(2:3)=prime do i=2, FLOOR(SQRT(REAL(N))) if(isPrime(i).eq.prime) then do j=i+i, N, i isPrime(j) = nonprime end do end if end do allocate(numlist(N)) numlist=(/(i,i=1,N)/) PrimeList=pack(numlist,isPrime(numlist).eq.prime) end subroutine get_prime program main implicit none interface subroutine get_prime(PrimeList, N) integer::N integer,allocatable::PrimeList(:) end subroutine get_prime end interface integer::N,iswin,i,j integer,parameter::win=1,lose=0 integer,allocatable::W(:),PrimeList(:) read *,N allocate(PrimeList(N)) call get_prime(PrimeList, N) allocate(W(2*N)) W(0:1)=win w(2:N)=lose do i=0, N if (W(i).eq.win) cycle do j=1, SIZE(PrimeList) W(i+PrimeList(j))=win end do end do if(w(N).eq.win) then print '(a)',"Win" else print '(a)',"Lose" end if end program main