Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math(LCM)

传送门


我自己是没有找到规律的,但是这种题放在第二题,要么暴力要么有规律,因此我们可以先对前几十个数暴力打表,然后就找到规律了,其证明如下,感谢Layton
在这里插入图片描述

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <bitset>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define lowbit(x) (x&(-x))
#define mkp(x,y) make_pair(x,y)
#define mem(a,x) memset(a,x,sizeof a);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;


int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}

int lcm(int a,int b){
    return a/gcd(a,b)*b;
}

void solve(int x,int &ansx,int &ansy){
    int ans=inf;
    for(int i=1;i<x;i++){
        int j=x-i;
        if(lcm(i,j)<ans){
            ans=lcm(i,j);
            ansx=min(i,j);
            ansy=max(i,j);
        }
    }
}

void table(){
    for(int i=2;i<=50;i++){
        int x,y;
        solve(i,x,y);
        cout<<i<<"---"<<x<<" "<<y<<endl;
    }
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        int ans=1;
        for(int i=2;i*i<=n;i++)
            if(n%i==0){
                int j=n/i;
                ans=max(ans,max(i,j));
            }
        cout<<ans<<" "<<n-ans<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值