結果

問題 No.28 末尾最適化
ユーザー simezi_tansimezi_tan
提出日時 2015-07-22 22:03:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 255 ms / 5,000 ms
コード長 986 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 150,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 21:24:17
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	int q; cin >> q;
	while(q--){
		int s, n, k, b, ans = inf;
		vi v;
		cin >> s >> n >> k >> b;
		v.pb(s);
		rep(i, n){
			s = 1 + ((ll)s * s + s * 12345ll) % ((int)1e8 + 9);
			v.pb(s);
		}
		
		for(int i = 2; i <= b; i++) if(b % i == 0){
			
			int c = 0;
			vi cnt;
			for(; b % i == 0; b /= i) c++;
			
			rep(l, n + 1){
				int k = 0;
				for(int j = v[l]; j % i == 0; j /= i) k++;
				cnt.pb(k);
			}
			sort(all(cnt));
			int x = 0;
			rep(l, k) x += cnt[l];
			ans = min(ans, x / c);
		}
		cout << ans << endl;
	}
	return 0;
}
0