結果
| 問題 | 
                            No.28 末尾最適化
                             | 
                    
| コンテスト | |
| ユーザー | 
                             yaoshimax
                         | 
                    
| 提出日時 | 2015-02-15 00:42:16 | 
| 言語 | Python2  (2.7.18)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 938 bytes | 
| コンパイル時間 | 145 ms | 
| コンパイル使用メモリ | 7,040 KB | 
| 実行使用メモリ | 14,320 KB | 
| 最終ジャッジ日時 | 2024-06-23 20:17:48 | 
| 合計ジャッジ時間 | 6,649 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 1 TLE * 1 | 
ソースコード
from heapq import heappush,heappop
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 = [[] 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,
         if len(hp[k]) < K:
            heappush(hp[k],-cnt)
         elif hp[k][0]<-cnt:
            heappop(hp[k])
            heappush(hp[k],-cnt)
      #print
      seed=x*x
      seed%=100000009
      seed+=x*12345
      seed%=100000009 
      seed+=1
   ans = 5000
   for j in range(len(ps)):
      curAns = 0
      for s in hp[j]:
         curAns-=s
      ans = min(ans,curAns/ps[j][1])
   print ans
            
            
            
        
            
yaoshimax