https://oj.csoj.tech/problem/3b định lí 4k+3

01/12/2022

ko an duoc full diem hic

Code
#include <bits/stdc++.h>
using namespace std;

bool isprime(int x){
	if (x < 2) return false;
	for (int iii = 2; iii <= sqrt(x); iii++){
		if (x%iii==0) return false;
	}
	return true;
}

int main(){
	int t;
	cin >> t;
	while (t>0) {
		t--;
		long long n;
		cin >> n;
		//solve
		long long max_n = n-1;
		long long u=-1;
		long long v=-1;
		while (sqrt(max_n) < n){
			if (isprime(max_n)) {
				max_n+=n;
				continue;
			}
			for (int i=2; i <= sqrt(max_n);i++){
				if ((max_n % i == 0) && (max_n/i < n)) {
					u=i;
					v=max_n/i;
				}
			}
			if (u != -1) {
				break;
			}
			max_n+=n;
		}
		cout << u << " " << v << '\n';
		
	}
	return 0;
}