Processing math: 100%
博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

题解 [CF803C] Maximal GCD

题面

解析

一开始以为这题很难的...

其实只要设da的最大公因数,

a[i]=s[i]d,

因为n=ni=1a[i]=ni=1s[i]d=dni=1s[i].

所以d一定是n的约数,

因此从大到小枚举d,

判断能否构造ks[i]就行了.

判断也很简单,

只要ki=1i=(k+1)k/2<=n/d,

然后将s[i=1~k1]=i,s[k]等于剩下的就好了.

(有点简陋但应该很好想吧...)

最后注意k大约大于200000时就直接不可能了.

要不然乘起来会爆longlong旁边的lzf大仙T个不停.

今天**地忘记排序结果懵逼地WA了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

inline int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}

const int N=200000;
int n,K;
int sta[N],top=0;

signed main(){
	n=read();K=read();
	if(K>=N){puts("-1");return 0;}
	if((K*(K+1)/2)>n){puts("-1");return 0;}
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			sta[++top]=i;
			if(i*i!=n) sta[++top]=n/i;
		}
	}
	sort(sta+1,sta+top+1);
	for(int i=top;i>=1;i--){
		int d=sta[i];
		int s=n/d;
		if((K*(K+1)/2)<=s){
			for(int j=1;j<K;j++) printf("%lld ",j*d),s-=j;
			printf("%lld\n",s*d);
			return 0;
		}
	}
	puts("-1");
	return 0;
}
posted @   Hastin  阅读(101)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示