B. GCD Problem(900分)

题目:

Given a positive integernn. Find threedistinct positive integersaa,bb,cc such thata+b+c=na+b+c=n andgcd(a,b)=cgcd⁡(a,b)=c, wheregcd(x,y)gcd⁡(x,y) denotes the greatest common divisor (GCD) of integersxx andyy.
Input
The input consists of multiple test cases. The first line contains a single integertt (1t1051≤t≤105) — the number of test cases. Description of the test cases follows.

The first and only line of each test case contains a single integernn (10n10910≤n≤109).
Output
For each test case, output threedistinct positive integersaa,bb,cc satisfying the requirements. If there are multiple solutions, you can print any. We can show that an answer always exists.

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&m);
        if(m%2!=0){
            int k=m/2;
            if(k%2==0){
                printf("%d %d 1\n",k-1,k+1);
            }
            else printf("%d %d 1\n",k-2,k+2);
        }
        else printf("%d %d 1\n",m/2-1,m/2);
    }
    return 0;
}

原文链接: https://www.cnblogs.com/happycrazy/p/15786718.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/184885

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 上午10:49
下一篇 2023年2月12日 上午10:49

相关推荐