結果

問題 No.3663 LCM Decomposition
コンテスト
ユーザー 👑 kmjp
提出日時 2026-09-02 00:22:41
言語 C++17
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 107 ms / 1,000 ms
+ 348µs
コード長 2,014 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,478 ms
コンパイル使用メモリ 230,868 KB
実行使用メモリ 9,752 KB
最終ジャッジ日時 2026-09-02 00:22:46
合計ジャッジ時間 3,738 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T;
ll N,L,R;
vector<int> cand[1<<9];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	while(T--) {
		int mask;
		FOR(mask,1<<9) cand[mask].clear();
		cin>>N>>L>>R;
		vector<int> V;
		for(i=1;i*i<=N;i++) if(N%i==0) {
			V.push_back(i);
			if(i*i!=N) V.push_back(N/i);
		}
		map<int,int> M;
		y=N;
		for(x=2;x*x<=y;x++) if(y%x==0) {
			M[x]=1;
			while(y%x==0) {
				M[x]*=x;
				y/=x;
			}
		}
		if(y>1) M[y]=y;
		vector<int> D;
		FORR2(a,b,M) D.push_back(b);
		int ND=D.size();
		FORR(v,V) {
			if(v<L||v>R) continue;
			mask=0;
			FOR(i,ND) if(v%D[i]==0) mask|=1<<i;
			cand[mask].push_back(v);
		}
		FOR(i,ND) {
			FOR(mask,1<<ND) {
				if(mask&(1<<i)) {
					FORR(a,cand[mask]) cand[mask^(1<<i)].push_back(a);
				}
			}
			FOR(mask,1<<ND) {
				if(cand[mask].size()>3) cand[mask].resize(3);
			}
		}
		vector<int> ret;
		FOR(mask,1<<ND) if(ret.empty()) {
			int ma=(1<<ND)-1-mask;
			for(int sm=mask;sm>=0;sm--) if(ret.empty()) {
				sm=sm&mask;
				int sm2=mask^sm;
				FORR(a,cand[ma]) FORR(b,cand[sm]) FORR(c,cand[sm2]) {
					if(a!=b&&a!=c&&b!=c) ret={a,b,c};
				}
			}
		}
		sort(ALL(ret));
		if(ret.empty()) cout<<-1<<endl;
		else cout<<ret[0]<<" "<<ret[1]<<" "<<ret[2]<<endl;
			
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0