QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#652927#9167. Coprime Arraywoodie_0064#WA 0ms3784kbC++201.3kb2024-10-18 19:19:332024-10-18 19:19:36

Judging History

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

  • [2024-10-18 19:19:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2024-10-18 19:19:33]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 3;
typedef long long ll;

void work(){
	int n,m;cin >> n >> m;
	vector <int> ans,r,a;
	if(n % 2 && m % 2 == 0) {
		ans.push_back(1);
		n -= 1;
	}
	for(int i = 2;i * i <= m;i++) if(m % i == 0) {
		r.push_back(i);
		while(m % i == 0) m /= i;
	}
	if(m) r.push_back(m);
	for(const auto &x : r) {
		if(n % x == 1) {
			a.push_back(2 % x);
		}else a.push_back(1);
	}
	
	auto exgcd = [] (auto &&self,ll a,ll b,ll &x,ll &y) {
		if(!b) {
			x = 1;y = 0;
			return a;
		}
		ll d = self(self,b,a % b,x,y);
		ll t = x;
		x = y;
		y = t - (a / b) * y;
		return d;
	};
	
	auto CRT = [&] () {
		int k = a.size();
		ll n = 1,res = 0;
		for(int i = 0;i < k;i++) {
			n = n * r[i];
//			cout << a[i] << ' ' << r[i] << '\n';
		}
		for(int i = 0;i < k;i++) {
			ll m = n / r[i],b,y;
			exgcd(exgcd,m,r[i],b,y);
			res = (res + a[i] * m * b % n) % n;
		}
		return (res % n + n) % n;
	};
	
	ans.push_back(CRT());
	ans.push_back(n - ans.back());
	cout << (int)ans.size() << '\n';
	for(auto &x : ans) cout << x << ' ';
	cout << '\n';
}


int main(){
//	freopen("test.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	while(T--){
		work();
	}	
	return 0;
}

詳細信息

Test #1:

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

input:

9 6

output:

3
1 1 7 

result:

ok Correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

14 34

output:

2
1 13 

result:

ok Correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

1000000000 223092870

output:

2
148728581 851271419 

result:

ok Correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

2 1000000000

output:

2
1 1 

result:

ok Correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

649557664 933437700

output:

2
83981 649473683 

result:

ok Correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

33396678 777360870

output:

2
1 33396677 

result:

ok Correct

Test #7:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

48205845 903124530

output:

3
1 18811 48187033 

result:

ok Correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

251037078 505905400

output:

2
1 251037077 

result:

ok Correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

30022920 172746860

output:

2
1 30022919 

result:

ok Correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

63639298 808058790

output:

2
248711 63390587 

result:

ok Correct

Test #11:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

76579017 362768406

output:

3
1 1 76579015 

result:

ok Correct

Test #12:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

40423669 121437778

output:

3
1 1 40423667 

result:

ok Correct

Test #13:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

449277309 720915195

output:

2
1 449277308 

result:

ok Correct

Test #14:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

81665969 919836918

output:

3
1 68069 81597899 

result:

ok Correct

Test #15:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

470578680 280387800

output:

2
1 470578679 

result:

ok Correct

Test #16:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

58450340 803305503

output:

2
1 58450339 

result:

ok Correct

Test #17:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

125896113 323676210

output:

3
1 59281 125836831 

result:

ok Correct

Test #18:

score: 0
Accepted
time: 0ms
memory: 3372kb

input:

381905348 434752500

output:

2
1 381905347 

result:

ok Correct

Test #19:

score: -100
Wrong Answer
time: 0ms
memory: 3480kb

input:

78916498 653897673

output:

2
121772 78794726 

result:

wrong answer Jury's answer is better than participant's