Educational Codeforces Round 20 C 数学/贪心/构造
1 second
256 megabytes
standard input
standard output
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1.
The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).
If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
6 3
1 2 3
8 2
2 6
5 3
-1 题意:构造一个递增的长度为k 和为n 的数列,gcd尽可能的大.
题解:gcd 从1~i 所以寻找长度为k 首项为i 等差为i 数列和为n的一个序列
细细考虑 n应当模尽i 那么枚举n的因子 check 一下 取最大的i
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll __int64
using namespace std;
ll n,k;
bool fun(ll s){
if(k*(k+)*s/>n)
return false;
if((n-k*(k-)*s/)%s==)
return true;
return false;
}
int main()
{
scanf("%I64d %I64d",&n,&k);
if(k>(*n/(+k)))
printf("-1\n");
else
{
ll e=;
for(ll i=;i*i<=n;i++){
if(n%i==&&fun(i)) e=max(e,i);
if(n%i==&&fun(n/i)) e=max(e,n/i);
}
for(int j=; j<k; j++)
printf("%I64d ",j*e);
printf("%I64d\n",n-k*(k-)*e/);
}
return ;
}
Educational Codeforces Round 20 C 数学/贪心/构造的更多相关文章
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- Educational Codeforces Round 53C(二分,思维|构造)
#include<bits/stdc++.h>using namespace std;const int N=1e6+6;int x[N],y[N];int sx,sy,n;char s[ ...
- Educational Codeforces Round 20 D. Magazine Ad
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...
- Educational Codeforces Round 20 C(math)
題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...
- Educational Codeforces Round 64 -B(贪心)
题目链接:https://codeforces.com/contest/1156/problem/B 题意:给一段字符串,通过变换顺序使得该字符串不包含为位置上相邻且在字母表上也相邻的情况,并输出. ...
- Educational Codeforces Round 15 D 数学推公式
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 20.C
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 C. Maximal GCD
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 B. Distances to Zero
B. Distances to Zero time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- 二叉树的深度<java版>
二叉树的结构 二叉树是比较常见的一种的一种数据结构. 首先看看二叉树的数据结构: //由左节点和右节点以及一个节点值构成 public class TreeNode{ TreeNode leftNod ...
- RabbitMQ各协议异同详解
一.官网介绍 Which protocols does RabbitMQ support? RabbitMQ supports several messaging protocols, directl ...
- HP Vitrual Connect 配置快速参考
使用任意浏览器,在地址栏输入VC的管理地址(如果不知道VC的管理地址请从OA中进入) 输入用户名和密码登入VC,验证成功后将进入VM的配置向导 点击"Next"继续,将先进行Dom ...
- docker应用容器化准则—12 factor
在云的时代,越来越多的传统应用需要迁移到云环境下,新应用也要求能适应云的架构设计和开发模式.而12-factor提供了一套标准的云原生应用开发的最佳原则. 在容器云项目中应用容器化主要参考12-Fac ...
- linux下搭建python机器学习环境
前言 在 linux 下搭建 python 机器学习环境还是比较容易的,考虑到包依赖的问题,最好建立一个虚拟环境作为机器学习工作环境,在建立的虚拟环境中,再安装各种需要的包,主要有以下6个(这是看这个 ...
- 5.airflow问题
1. Traceback (most recent call last): File "/usr/bin/airflow", line 28, in <module> ...
- 软工实践第八次作业(课堂实战)- 项目UML设计(第五组)
本次作业博客 团队信息 队名:起床一起肝活队 原组长: 白晨曦(101) 原组员: 李麒 (123) 陈德斌(104) 何裕捷(214) 黄培鑫(217) 王焕仁(233) 林志华(128) 乐忠豪( ...
- sql主表分页查询关联子表取任意一条高效方案
有个业务场景,主表中一条数据,在子表中有多条详情数据.对数据进行展示的时候,产品希望随意拿一条子表的数据关联展示出来,用了很多方案,但是都不够好. sql查询取子表任意一条,多个字段的方案 最终找到一 ...
- centos 6 编译emacs-24.5
yum install `yum deplist emacs | grep provider | awk -F: '{print $2}' | awk '{print $1}' | xargs` yu ...
- Google Professional Data Engineer(PDE)考试
在国内参加PDE考试的人比较少,导致资料也很少.我在19年1月30号去上海参加PDE考试,参加前也是完全没底,因为时间短资料少,但幸运的是顺利通过了.回过头来看,其中有些技巧和重点,在此做一些总结,希 ...