QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#451125 | #6823. Coffee Overdose | PetroTarnavskyi# | WA | 0ms | 3548kb | C++20 | 1.2kb | 2024-06-22 21:20:27 | 2024-06-22 21:20:27 |
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 unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
ULL mod;
ULL mult(ULL a, ULL b)
{
return a * b % mod;
}
ULL add(ULL a, ULL b)
{
return a + b < mod ? a + b : a + b - mod;
}
ULL sub(ULL a, ULL b)
{
return a - b >= 0 ? a - b : a - b + mod;
}
const int N = 1 << 21;
int was[N];
ULL Q;
bool solve()
{
fill(was, was + Q, -1);
ULL a, b;
cin >> a >> b;
a %= mod;
b %= mod;
vector<ULL> vals;
vals.reserve(Q);
was[a % Q] = SZ(vals);
vals.PB(a);
while(true)
{
a = add(mult(a, a), b);
if(was[a % Q] != -1)
{
ULL prev = vals[was[a % Q]];
ULL d = sub(a, prev);
return gcd(d, mod) == Q;
}
was[a % Q] = SZ(vals);
vals.PB(a);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> mod >> Q >> t;
while(t--)
cout << solve();
cout << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3548kb
input:
4 1 2 2 1 10 4 172800 172800
output:
10
result:
wrong answer 1st words differ - expected: '2', found: '10'