結果

問題 No.28 末尾最適化
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-15 00:46:08
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 825 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 6,664 KB
実行使用メモリ 11,308 KB
最終ジャッジ日時 2023-09-06 01:11:47
合計ジャッジ時間 6,634 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,044 KB
testcase_01 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

Q=int(raw_input())
primes=[2,3,5,7,11,13,17,19,23,29]
for i in range(Q):
   seed,N,K,B=map(int,raw_input().split())
   ps=[]
   for p in primes:
      cnt=0
      while B%p==0:
         cnt+=1
         B/=p
      if cnt>0:
         ps.append((p,cnt))
   hp = [[0 for k in range(N+1)] for j in range(len(ps))]
   for j in range(N+1):
      x=seed
      #print x,
      for k in range(len(ps)):
         p=ps[k][0]
         cnt=0
         while seed%p == 0:
            seed/=p
            cnt+=1
         #print cnt,
         hp[k][j]=cnt
      #print
      seed=x*x
      seed%=100000009
      seed+=x*12345
      seed%=100000009 
      seed+=1
   ans = 5000
   for j in range(len(ps)):
      hp[j].sort()
      curAns = 0
      for k in range(K):
         curAns+=hp[j][k]
      ans = min(ans,curAns/ps[j][1])
   print ans

0