QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#451129 | #6824. Demonstrational Sequences | PetroTarnavskyi# | WA | 2ms | 9360kb | C++20 | 1.2kb | 2024-06-22 21:23:11 | 2024-06-22 21:23:11 |
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: 100
Accepted
time: 0ms
memory: 3592kb
input:
15 5 5 1 1 1 2 2 4 4 8 8 16
output:
11010
result:
ok "11010"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9360kb
input:
998244352 1048576 3 2022 924 12345678 1234567 23333333 6666666
output:
001
result:
ok "001"
Test #3:
score: 0
Accepted
time: 1ms
memory: 4152kb
input:
100237 100237 10 1244422970085542683 6256585832417115176 11178595626727644735 679276059713497324 5646838801370008540 6709514788466664568 9971158657914728691 8724448042786063799 9867649407902336110 2614925263502318093 1990105069810770727 8671216841234378816 7965667786524489724 6722337513023700570 246...
output:
1111111111
result:
ok "1111111111"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
1000000007 1 200 1244424352052424851 13102057264748565738 10964128241743967010 11238647915096906960 9602909082986968021 14247804011443894396 13231275623402659328 11122445945926639224 1819715673773979255 15011227386780949150 10389668459305004672 13595253579372877142 136927098471150438 141908708541553...
output:
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
result:
ok "111111111111111111111111111111...1111111111111111111111111111111"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 1 200 1244422970079336291 4707347560601392081 16633665001192110076 15773758607538398243 11070497290011093392 11929979209055974561 8355738147346006300 6479245221430563815 10109334084151275293 11867087657669754231 17442584295523326999 11181890936205849132 9065910826445511105 4364106058213150008 3158...
output:
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
result:
ok "111111111111111111111111111111...1111111111111111111111111111111"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3548kb
input:
1829276567 1223 200 1244422970077270675 3806627635127557106 13984072790700162529 11560843058580181248 18218320506679528544 11095342096011758221 4400021764111680243 2513593206800052431 18199847053143773541 12194057128449124778 13449463383710867755 15111229049249507634 9142159878193341647 851735763810...
output:
11010011000111010001000010010100100000100101001010111000110110001100010100011010000110000001111111101010110010010100110110110011100011101110101100111011100110010001001010011010000000001001000111010011
result:
wrong answer 1st words differ - expected: '111111111111111111111111111111...1111111111111111111111111111111', found: '110100110001110100010000100101...0011010000000001001000111010011'