题意: 找出 A + B = n A+B=n A+B=n并且 lcm ( A , B ) \operatorname{lcm}(A,B) lcm(A,B)最小的 A A A和 B B B。
思路: n n n为偶数的时候答案肯定为都是 n 2 \frac{n}{2} 2n。当 n n n为奇数的时候,我们假设 x x x为 n n n的一个因子,那么 n m o d x = = 0 n \bmod x==0 nmodx==0 且 ( n − x ) m o d x = = 0 (n-x) \bmod x==0 (n−x)modx==0 ,那么 lcm ( x , n − x ) = n − x \operatorname{lcm}(x,n-x)=n-x lcm(x,n−x)=n−x,我们要让 lcm \operatorname{lcm} lcm尽可能小,就需要让 x x x尽可能大,所以只需要找 n n n最大因子即可。
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n;
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
int _; scanf("%d",&_);
while(_--)
{
scanf("%d",&n);
if(n%2==0) printf("%d %d\n",n/2,n/2);
else
{
int ans=-1;
for(int i=2;i<=n/i;i++)
if(n%i==0)
{
ans=i;
break;
}
if(ans==-1) ans=1;
else ans=n/ans;
printf("%d %d\n",ans,n-ans);
}
}
return 0;
}
/*
*/