QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#451125#6823. Coffee OverdosePetroTarnavskyi#WA 0ms3548kbC++201.2kb2024-06-22 21:20:272024-06-22 21:20:27

Judging History

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

  • [2024-06-22 21:20:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3548kb
  • [2024-06-22 21:20:27]
  • 提交

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'