QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#335976#8103. Productucup-team1209#ML 29ms6948kbC++201.3kb2024-02-24 10:48:352024-02-24 10:48:35

Judging History

你现在查看的是最新测评结果

  • [2024-02-24 10:48:35]
  • 评测
  • 测评结果:ML
  • 用时:29ms
  • 内存:6948kb
  • [2024-02-24 10:48:35]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = __uint128_t;
using i128 = __int128_t;
std::vector<int> ps;
const int M = 1e6;

u64 pms[M];
int cc;

ll n;

bool ins(u64 x) {
	for(int i = 0;i < cc;++i) {
		if((i128) pms[i] * x <= n) {
			if(cc == M) {
				return 0;
			}
			pms[cc++] = pms[i] * x;
		}
	}
	return 1;
}
int idx;

ll check(ll n) {
	for(int i : ps) {
		for(;(u64)n % (u32)i == 0;) n /= i;
	}
	return n == 1;
}
ll ans = 1;
void dfs(ll x, int id) {
	if(id < idx) {
		ll z = std::upper_bound(pms, pms + cc, n / x)[-1];
		ans = std::max(ans, z * x);
		return ;
	}
	for(;;) {
		dfs(x, id - 1);
		if((i128)x * ps[id] > n) {
			break;
		}
		x *= ps[id];
	}
}
void guess(ll n) {
	for(int i = 0;i < 2e5 && !check(n);--n, ++i);
	if(check(n)) {
		cout << n << '\n';
		exit(0);
	}
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	int k; cin >> k >> n;
	ps.resize(k);
	for(int & x : ps) cin >> x;
	guess(n);
	*pms = 1, cc = 1;
	sort(ps.begin(), ps.end());
	for(idx = 0;idx < (int) ps.size();++idx) {
		if(!ins(ps[idx])) break;
	}
	std::sort(pms, pms + cc);
	dfs(1, ps.size() - 1);
	cout << ans << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

3 30
2 3 7

output:

28

result:

ok 1 number(s): "28"

Test #2:

score: 0
Accepted
time: 29ms
memory: 6948kb

input:

7 939341491978215167
2 3 19 43 47 53 61

output:

939207819748596228

result:

ok 1 number(s): "939207819748596228"

Test #3:

score: -100
Memory Limit Exceeded

input:

16 997257405471326207
2 3 5 11 19 23 37 41 47 53 59 61 73 79 89 97

output:

997257095125632000

result: