結果

問題 No.7 プライムナンバーゲーム
ユーザー jjjj
提出日時 2016-07-24 02:41:40
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,179 bytes
コンパイル時間 1,800 ms
コンパイル使用メモリ 34,816 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:01:29
合計ジャッジ時間 2,256 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,692 KB
testcase_01 AC 1 ms
6,692 KB
testcase_02 AC 3 ms
6,692 KB
testcase_03 AC 1 ms
6,692 KB
testcase_04 AC 1 ms
6,692 KB
testcase_05 AC 1 ms
6,688 KB
testcase_06 AC 2 ms
6,692 KB
testcase_07 AC 1 ms
6,692 KB
testcase_08 AC 1 ms
6,692 KB
testcase_09 AC 2 ms
6,692 KB
testcase_10 AC 1 ms
6,692 KB
testcase_11 AC 2 ms
6,692 KB
testcase_12 AC 2 ms
6,692 KB
testcase_13 AC 2 ms
6,692 KB
testcase_14 AC 3 ms
6,696 KB
testcase_15 AC 3 ms
6,692 KB
testcase_16 AC 2 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

subroutine get_prime(PrimeList, N)
  implicit none
  integer::i,j,N
  integer,parameter::prime=1,nonprime=0
  integer,allocatable::isPrime(:), PrimeList(:)
  integer,allocatable::numlist(:)

  allocate(numlist(N))
  allocate(isPrime(N))

  isPrime=prime
  isPrime(1)=nonprime
  isPrime(2)=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

  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,i,j
  integer,parameter::win=1,lose=0
  integer,allocatable::W(:),PrimeList(:)

  read *,N
  allocate(PrimeList(N))
  call get_prime(PrimeList, N)

  allocate(W(0:2*N))

  W(0:1)=win
  w(2: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
0