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项数列使其满足:
1.各项之和为n 2.单增 3.最大公约数最大化。
思路:枚举n的因子q,找到满足n/q>=k*(k+1)/2 的最大q, 输出数列
PS:这题坑点挺多的。。比如数据范围 n,k 都是1e10 特判要考虑到这点。
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define db double
using namespace std;
;
;
int main()
{
ll n,k;
db s=sqrt(2.0);
scanf("%lld%lld",&n,&k);
ll ans=n;
)/) {//必须要判断k的值,否则会溢出。
puts("-1");
;
}
ll ma=;
;i<=sqrt(n);i++){
&&n/i>=k*(k+)/){ //i,n/i都可能是最大因子
ma=max<ll>(ma,i);
)/) ma=max<ll>(ma,n/i);
}
}
;i<k;i++){
printf("%lld ",i*ma);
ans-=i*ma;
}
printf("%lld\n",ans);
}
Educational Codeforces Round 20.C的更多相关文章
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- 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 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 ...
- Educational Codeforces Round 20 A. Maximal Binary Matrix
A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 20 E - Roma and Poker(dp)
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...
- Educational Codeforces Round 20 B
Description You are given the array of integer numbers a0, a1, ..., an - 1. For each element find th ...
随机推荐
- iOS安全攻防之使用 Charles 进行网络数据抓包 和 Paros 网络抓包
Charles 是 Mac 系统下常用的网路抓包工具(Paros 也不错),windows 下常用 fiddler.正版的 Charles 是收费的(PS:支持正版),天朝人民比较喜欢破解版的Char ...
- node async基础1
async的基础使用 1 async each 语法格式each(collection, iteratee, [callback]) 用途:遍历集合中的元素,并行对每个元素执行一定的操作,但是 ...
- 小K的H5之旅-HTML5与CSS3部分新属性浅见
一.HTML部分 1.HTML5新特点 向下兼容.用户至上.化繁为简.无插件范式.访问通用性.引入语义.引入原生媒体支持.引入可编程内容 2.HTML5标签语法 可以省略的元素:空元素语法的元素{br ...
- Android WebView 不支持 H5 input type="file" 解决方法
最近因为赶项目进度,因此将本来要用原生控件实现的界面,自己做了H5并嵌入webview中.发现点击H5中 标签 不能打开android资源管理器. 通过网络搜索发现是因为 android webvie ...
- c++概括
c++到底是什么样的语言 在过去的几十年,计算机技术的发展令人吃惊,当前的笔记本电脑的计算速度和存储信息的能力超过了20世纪60年代的大型机.20世纪七十年代,C和Pascal语言引领人们进入结构化编 ...
- Bottle源码阅读笔记(一):WSGI
前言 Bottle是一个Python Web框架.整个框架只有一个文件,不到4k行的代码,没有Python标准库以外的依赖,却包含了路由.模板和插件等Web框架常用功能.通过阅读Bottle源码来了解 ...
- cpp(第七章)
1.c++提供了3种表示c—风格字符串方法:字符数组,字符串常量,字符串指针.其中字符数组并不一定是字符串,以空值字符'\0'来结束的字符数组时字符串. 2.函数参数为数组时,虽然减少了时间和内存的使 ...
- 封装TableView有可能用到的数据结构和UITableViewCell的一个继承类
最近4年的时间,我已经做了5个App完全独立开发, 工作经历5个App, 维护了两个App. 在这期间用的最多的是UITableView, 因此也有许多感觉可以封装的. 现在就是我封装的. RXCel ...
- HTTP协议入门
1.概述 (1)HTTP是应用层协议,是从Web服务器传输超文本到本地浏览器的传送协议,端口号为80.(2)默认情况下HTTP使用TCP,但是也可以基于以后存在的其他可靠传输协议.由于UDP无法提供可 ...
- 面向对象的SOLID原则白话篇
面向对象的SOLID原则 简介 缩写 全称 中文 S The Single Responsibility Principle 单一责任原则 O The Open Closed Principle 开放 ...