QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500667 | #3815. Weak pseudorandom generator | PetroTarnavskyi# | WA | 1ms | 3672kb | C++20 | 1.2kb | 2024-08-01 17:35:41 | 2024-08-01 17:35:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int MAGIC = 21;
LL fact[MAGIC];
unordered_set<LL> s[MAGIC];
LL maxDen[MAGIC];
void rec(int sum, int last, LL prod)
{
assert(sum < MAGIC);
s[sum].insert(prod);
maxDen[sum] = max(maxDen[sum], prod);
FOR(x, last, MAGIC - sum)
rec(sum + x, x, prod * fact[x]);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
fact[0] = 1;
FOR(i, 1, MAGIC)
{
fact[i] = fact[i - 1] * i;
}
rec(0, 1, 1);
LL n;
cin >> n;
LL ans = n;
FOR(sum, 2, MAGIC)
{
__int128 num = fact[sum];
for (LL k = sum; ; k++)
{
__int128 d = num / n;
if (d > maxDen[sum])
break;
if (num % n == 0 && s[sum].count(d))
ans = min(ans, k);
num = num / (k - sum + 1) * (k + 1);
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3672kb
input:
5 3 2 1 0
output:
5
result:
wrong answer not correct, f_k = 2 but expected 0