RT,不知道为什么 WA 0 了 /kk
代码:
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N = 9, M = (1 << 7) - 1, K = 15 + 7;
int test_prime[N + 7] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23};
ll p[K], p_pow_k[K];
inline ll quick_pow(ll x, ll p, ll mod){
ll ans = 1;
while (p){
if (p & 1) ans = (lll)ans * x % mod;
x = (lll)x * x % mod;
p >>= 1;
}
return ans;
}
inline bool miller_rabin(ll n, ll k){
ll nd = n - 1, m = nd;
while (m){
ll x = quick_pow(k, m, n);
if (x != 1 && x != nd) return false;
if ((m & 1) == 1 || x == nd) return true;
m >>= 1;
}
return true;
}
inline bool is_prime(ll n){
if (n < 2) return false;
for (register int i = 1; i <= N; i++){
if (n == test_prime[i]) return true;
if (!miller_rabin(n, test_prime[i])) return false;
}
return true;
}
inline ll floyd(ll a, ll b, ll p){
return ((lll)a * a % p + b) % p;
}
ll gcd(ll a, ll b){
return b == 0 ? a : gcd(b, a % b);
}
inline ll pollard_pho(ll n){
ll x = 0, c = rand() % (n - 1) + 1;
for (register int i = 1; ; i <<= 1){
ll y = 1, z = x, ans;
for (register int j = 1; j <= i; j++){
x = floyd(x, c, n);
y = (lll)y * abs(x - z) % n;
if (j % M == 0){
ans = gcd(n, y);
if (ans > 1) return ans;
}
}
ans = gcd(n, y);
if (ans > 1) return ans;
}
}
void decompand(ll n, ll ans[], int &cnt){
if (n < 2) return;
if (is_prime(n)){
ans[++cnt] = n;
return;
}
ll factor;
do {
factor = pollard_pho(n);
} while (factor == n);
while (n % factor == 0){
n /= factor;
}
decompand(n, ans, cnt);
decompand(factor, ans, cnt);
}
inline ll max(ll a, ll b){
return a > b ? a : b;
}
ll dfs(ll n, int cnt, ll cur, int depth){
if (depth > cnt || cur * cur > n) return 0;
int depth_i = depth + 1;
return max(cur, max(dfs(n, cnt, cur, depth_i), dfs(n, cnt, cur * p_pow_k[depth], depth_i)));
}
int main(){
ll a, b;
while (cin >> a >> b){
int cnt = 0;
ll x = b / a, y, t = x;
srand(time(NULL));
decompand(x, p, cnt);
sort(p + 1, p + cnt + 1);
cnt = unique(p + 1, p + cnt + 1) - p - 1;
for (register int i = 1; i <= cnt; i++){
p_pow_k[i] = 1;
while (t % p[i] == 0){
t /= p[i];
p_pow_k[i] *= p[i];
}
}
y = dfs(x, cnt, 1, 1);
cout << y * a << " " << x / y * a << endl;
}
return 0;
}