Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math 数学
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math 数学
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳送門
題意: 找出A+B=nA+B=nA+B=n并且lcm?(A,B)\operatorname{lcm}(A,B)lcm(A,B)最小的AAA和BBB。
思路: nnn為偶數的時候答案肯定為都是n2\frac{n}{2}2n?。當nnn為奇數的時候,我們假設xxx為nnn的一個因子,那么nmodx==0n \bmod x==0nmodx==0 且 (n?x)modx==0(n-x) \bmod x==0(n?x)modx==0 ,那么lcm?(x,n?x)=n?x\operatorname{lcm}(x,n-x)=n-xlcm(x,n?x)=n?x,我們要讓lcm?\operatorname{lcm}lcm盡可能小,就需要讓xxx盡可能大,所以只需要找nnn最大因子即可。
//#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; } /**/ 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math 数学的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如约而至的意思 词语如约而至什么意思
- 下一篇: 草原的作者 草原的作者简介