codeforces 803c
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 803c相关的知识,希望对你有一定的参考价值。
题意:给出n,k,求k个严格递增的数,使得k个数之和等于n,并且要求k个数的gcd最大
思路:k*(k+1)/2 * gcd <= n,gcd是n的因子,先找出n的所有因子,然后找到最大的一个满足条件的
AC代码:
#include "iostream" #include "iomanip" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define step(x) fixed<< setprecision(x)<< #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define ll long long #define endl ("\n") #define ft first #define sd second #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const ll mod=1e9+7; const ll INF = 1e18+1LL; const int inf = 1e9+1e8; const double PI=acos(-1.0); const int N=1e5+100; ll n,k,t,u,gcd,g[N]; int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>k; if(k>500000){ cout<<"-1"; return 0; } u=k*(k+1)/2; for(ll i=1; i*i<=n; ++i){ if(n%i==0){ if(i*i==n) g[++t]=i; else{ g[++t]=i, g[++t]=n/i; } } } for(int i=1; i<=t; ++i){ if(u<=n/g[i] && g[i]>gcd){ gcd=g[i]; } } if(gcd==0) cout<<"-1"; else{ ll v=n/gcd, last=v-u+k; for(int i=1; i<k; ++i) cout<<i*gcd<<" "; cout<<last*gcd<<endl; } return 0; }
以上是关于codeforces 803c的主要内容,如果未能解决你的问题,请参考以下文章
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段
Codeforces 86C Genetic engineering(AC自动机+DP)