首页 > 其他分享 >Educational Codeforces Round 20-C. Maximal GCD

Educational Codeforces Round 20-C. Maximal GCD

时间:2023-06-12 18:05:18浏览次数:40  
标签:Maximal 约数 Educational 20 sequence ll numbers input output


原题链接


C. Maximal GCD



time limit per test



memory limit per test



input



output


n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n

Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.

-1.


Input



n and k (1 ≤ n, k ≤ 1010).


Output



k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.


Examples



input



6 3



output



1 2 3



input



8 2



output



2 6



input



5 3



output



-1


遍历n的所有约数,找到最大的约数m,满足 i = n / m 使得(k+1)*k/2<=i

那么约数m就是数列的最大公约数


#include <bits/stdc++.h>
#define maxn 100005
typedef long long ll;
using namespace std;


bool judge(ll i, ll k) {
	if((k+1) <= 2*i/k)
	 return true;
	return false;
}
int main() {
	//freopen("in.txt", "r", stdin);
	ll n, k, maxs = 0;
	scanf("%I64d %I64d", &n, &k);
	for(ll i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			ll m = n / i;
			if(judge(m, k))
			  maxs = max(i, maxs);
			if(judge(i, k))
			 maxs = max(m, maxs);
		}
	}
	if(maxs == 0) {
		puts("-1");
		return 0;
	}
	ll cnt = 1;
	ll m = n / maxs;
	int first = 0;
	for(int i = 1; i <= k; i++) {
		if(first)
		 putchar(' ');
		if(i != k)
		 printf("%I64d",cnt * maxs);
		else{
		 cnt--;
		 printf("%I64d",(m - (1+cnt)*cnt/2) * maxs);
		}
		cnt++;
		first = 1;
	}
	return 0;
}




标签:Maximal,约数,Educational,20,sequence,ll,numbers,input,output
From: https://blog.51cto.com/u_16158872/6464563

相关文章

  • Looksery Cup 2015-H. Degenerate Matrix(浮点数二分)
    原题链接H.DegenerateMatrixtimelimitpertestmemorylimitpertestinputoutputdeterminant ofamatrix 2 × 2degeneratenorm ||A|| ofamatrix AYouaregivenamatrix .Consideranydegeneratemat......
  • Educational Codeforces Round 7-D. Optimal Number Permutation
    原题链接D.OptimalNumberPermutationtimelimitpertestmemorylimitpertestinputoutputYouhavearray a thatcontainsallintegersfrom 1 to n twice.Youcanarbi......
  • Educational Codeforces Round 4-D. The Union of k-Segments
    原题链接D.TheUnionofk-SegmentstimelimitpertestmemorylimitpertestinputoutputYouaregiven n segmentsonthecoordinateaxis Ox andthenumber k.Thepoint......
  • Educational Codeforces Round 5-E. Sum of Remainders
    原题链接E.SumofRemainderstimelimitpertestmemorylimitpertestinputoutputCalculatethevalueofthesum: n mod 1 + n mod 2 + n mod 3 +...+ n mod m......
  • 2023年度Linux系统安装与移除JDK保姆级教程
    简介本篇文章介绍了如何在CentOS系统上安装与移除JDK,并提供了两种不同的安装与移除方法。我们还将针对每种方法的优点和缺点进行对比前置条件在开始之前,请确保您已经在虚拟机中安装CentOS系统如果没有安装请参考我之前的VMwareWorkstation17Pro安装配置CentOS7与ssh......
  • 2023年度Linux安装与移除tomcat保姆级教程
    前言Tomcat是一个流行的JavaServlet容器,用于开发和部署JavaWeb应用程序。本文将介绍如何在CentOS操作系统上安装与移除Tomcat,并提供了逐步说明以及相关命令。读者需要具备一定的Linux基础知识,如使用命令行工具等。安装前置条件在开始安装Tomcat之前,请确保您已满足以下条件:......
  • 2020-09-10 mysql主从复制
    mysql主从复制解决问题:高并发,灾难恢复,读写分离,故障转移mysql01mysql02数据实时同步:是通过执行的dmlsql语句(包括增删改),写入到二进制日志binlog文件中,来实现数据同步的.从数据库开启一个io线程读取主数据库中的binlog文件,读取到后,开启一个sql线程,执行binlog文件.达......
  • 2020-07-03 java配置环境变量
    java开发,首先要安装JDK,并配置环境1 安装JDK(本人下载的安装包,无脑下一步,选择了下文件夹),安装完成截图如下2 开始配置环境变量右键我的电脑==高级系统设置==环境变量==系统变量中选择新建 (1)JAVA_HOME路径根据自己安装的写,路径到(bin 上一层)例如:笔者的jdk 的bin......
  • 2020-10-26 多线程学习1
    join关键字测试:publicclassTestJoin{publicstaticvoidmain(String[]args)throwsInterruptedException{//TODOAuto-generatedmethodstubfor(inti=0;i<3;i++){ThreadTestt1=newThreadTest("A");......
  • AD20 的图层分类
    ①、与电气属性相关的层:2类层一、toplayer-顶层&  bottomlayer-底层板子顶层的金属布线;板子底层的金属布线二、multilayer多层一个抽象层电路板上焊盘和穿透式过孔要穿透整个电路板,与不同的导电图形层建立电气连接关系,因此系统专门设置了一个抽象的层—多层。一......