EhAb AnD gCd

EhAb AnD gCd

题面翻译

给你一个数 x x x,输出一组 ( a , b ) (a,b) (a,b) 使得 a a a b b b 的最大公约数和最小公倍数的和为 x x x,若有多种答案,输出任意一种即可。

第一行输入一个 t t t,有 t t t 组数据,之后每组数据输入一个数 x x x

对于每组数据,输出两个用一个空格隔开的数 a a a, b b b。若有多种答案,输出任意一种即可。

题目描述

You are given a positive integer $ x $ . Find any such $ 2 $ positive integers $ a $ and $ b $ such that $ GCD(a,b)+LCM(a,b)=x $ .

As a reminder, $ GCD(a,b) $ is the greatest integer that divides both $ a $ and $ b $ . Similarly, $ LCM(a,b) $ is the smallest integer such that both $ a $ and $ b $ divide it.

It’s guaranteed that the solution always exists. If there are several such pairs $ (a, b) $ , you can output any of them.

输入格式

The first line contains a single integer $ t $ $ (1 \le t \le 100) $ — the number of testcases.

Each testcase consists of one line containing a single integer, $ x $ $ (2 \le x \le 10^9) $ .

输出格式

For each testcase, output a pair of positive integers $ a $ and $ b $ ( $ 1 \le a, b \le 10^9) $ such that $ GCD(a,b)+LCM(a,b)=x $ . It’s guaranteed that the solution always exists. If there are several such pairs $ (a, b) $ , you can output any of them.

样例 #1

样例输入 #1

2
2
14

样例输出 #1

1 1
6 4

提示

In the first testcase of the sample, $ GCD(1,1)+LCM(1,1)=1+1=2 $ .

In the second testcase of the sample, $ GCD(6,4)+LCM(6,4)=2+12=14 $ .

不得不承认方向的重要性
错解:
我以为只要把最小公倍数看作最大公因数乘a的另一个对应因数乘b的另一个对应因数,由于公因数已经最大,所以a与b对应的另一个因数互质。
但是这样的话,相当麻烦。
写了很久的代码。
事实上,既然题目只要求输出一组,那么只要想一组特殊值即可。比如这两个数的其中一个数为1,那么最大公因数为1,最小公倍数为另一个数字。他们的和就是1加另一个数字。如此

#include<stdio.h>
int main(void)
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		long long x;
		scanf("%lld", &x);
		printf("1 %lld\n", x - 1);
	}
	return 0;
}
  • 26
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值