题解 |#牛客春招刷题训练营# 游游的最小公倍数

游游的最小公倍数

https://www.nowcoder.com/practice/385c7aa397e54bb58f36286ab0d65156

#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <numeric>
#include <ctime>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;

const ll N = 1e5 + 5, mod = 1e9 + 7, inf = 2e18;

ll n, a, b;

bool check(int n) {
    if (n == 1)return false;
    if (n == 2)return true;

    if (n % 2 == 0)return false;

    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)return false;
    }

    return true;
}

void solve() {
    cin >> n;

    ll ansx = n / 2, ansy;
    ansy = n - ansx;

    bool flag = true;
    while (flag) {
        if (__gcd(ansx, ansy) == 1) {
            flag = false;
            ansx++;
            ansy--;
        }
        ansx--;
        ansy++;
    }


    cout << ansx << ' ' << ansy << '\n';
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}


全部评论

相关推荐

炫哥_:为什么都读硕士了?项目还是网上的项目(真心发问)
最后再改一次简历
点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务