QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#239621#7688. Alea Iacta Estucup-team197#WA 171ms63156kbC++142.1kb2023-11-04 21:55:002023-11-04 21:55:00

Judging History

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

  • [2023-11-04 21:55:00]
  • 评测
  • 测评结果:WA
  • 用时:171ms
  • 内存:63156kb
  • [2023-11-04 21:55:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=1e6+5;
const int iu=1e6;
vector<int>pf[N];
ll n,m;
vector<ll>v;
void gen(vector<pair<ll,ll> >&g,int id,ll cur){
	if(id==g.size()){
		v.push_back(cur);
		return;
	}
	for(int i=0; i<g[id].fi ;i++){
		ll dx=i*g[id].se;
		gen(g,id+1,cur+dx);
	}
}
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
void solve(){
	cin >> n >> m;
	if(n>m) swap(n,m);
	if(n==1 && pf[m].size()<=1){
		cout << "0\n0\n";
		return;
	}
	ll xs=n;
	for(ll s=n+1; s<=m ;s++){
		if(s*s>n*m) break;
		if(n*m%s==0) xs=s;
	}
	ll g=gcd(n,m);
	vector<pair<ll,ll> >gl,gr;
	if(xs==n && g!=1){
		ll p=pf[g][0];
		for(int i=0; i<pf[n].size() ;i++){
			if(pf[n][i]==p){
				swap(pf[n][0],pf[n][i]);
				break;
			}
		}
		{
			ll step=1;
			for(auto c:pf[n]){
				gl.push_back({c,step});
				step*=c;
			}
		}
		for(int i=0; i<pf[m].size() ;i++){
			if(pf[m][i]==p){
				swap(pf[m][0],pf[m][i]);
				break;
			}
		}
		swap(pf[m][0],pf[m].back());
		{
			ll step=1;
			for(auto c:pf[m]){
				gr.push_back({c,step});
				step*=c;
			}
		}
		swap(gl[0],gr.back());
	}
	else{
		if(xs==n){
			xs--;
			while(n*m%xs!=0) --xs;
		}
		vector<pair<ll,ll> >gn;
		{
			ll step=1;
			for(auto c:pf[n]){
				gn.push_back({c,step});
				step*=c;
			}
		}
		{
			ll step=1;
			for(auto c:pf[m]){
				gn.push_back({c,step});
				step*=c;
			}
		}
		for(auto c:gn){
			if(xs%c.fi==0){
				xs/=c.fi;
				gl.push_back(c);
			}
			else gr.push_back(c);
		}
	}
	
	v.clear();
	gen(gl,0,0);
	cout << v.size() << ' ';
	for(auto c:v) cout << c+1 << ' ';
	cout << '\n';
	v.clear();
	gen(gr,0,0);
	cout << v.size() << ' ';
	for(auto c:v) cout << c+1 << ' ';
	cout << '\n';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	for(int i=2; i<=iu ;i++){
		if(!pf[i].empty()) continue;
		for(int j=i; j<=iu ;j+=i){
			int z=j;
			while(z%i==0){
				z/=i;
				pf[j].push_back(i);
			}
		}
	}
	int t;cin >> t;
	while(t--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 171ms
memory: 62940kb

input:

3
2 8
1 9
2 9

output:

4 1 2 2 3 
4 1 5 3 7 
3 1 2 3 
3 1 4 7 
3 1 2 3 
6 1 4 7 2 5 8 

result:

ok Correct. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 167ms
memory: 63156kb

input:

1
40013 40013

output:

40013 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...

result:

wrong answer Same as input (test case 1)