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 ...
随机推荐
- python-python爬取妹子图片
# -*- conding=utf-8 -*- import requests from bs4 import BeautifulSoup import io url = "https:// ...
- Linux环境下Java应用性能分析定位-CPU使用篇
1 CPU热点分析定位背景 CPU资源还是很昂贵的,为了深刻感受到这种昂贵,间下图当前CPU的资源售价: 所以对于程序猿们来说,需要让程序合理高效的使用CPU资源.利用有限的CPU资源来解决完 ...
- Python 代码调试技巧
使用 pdb 进行调试 pdb 是 python 自带的一个包,为 python 程序提供了一种交互的源代码调试功能,主要特性包括设置断点.单步调试.进入函数调试.查看当前代码.查看栈片段.动态改变变 ...
- 《C》数组
数组 数组方法: var arr = [1, 2, 3]; arr.push(4)://arr='[1, 2, 3, 4]' 向末尾添加一个或者多个元素 arr.pop()://删除末位元素 var ...
- C#中委托的理解
请注意,这只是个人关于C#中委托的一点点理解,参考了一些博客,如有不周之处,请指出,谢谢! 委托是一种函数指针,委托是方法的抽象,方法是委托的实例.委托是C#语言的一道坎,明白了委托才能算是C#真正入 ...
- 前端系列之HTML基础知识概述
1.什么是HTML HTML:Hyper Text Markup Language :超文本标记语言. 超文本:功能比普通文本更加强大. 标记语言:使用一组标签对内容进行描述的语言,它不是编程语言. ...
- 第一章 JavaScript简介
DOM级别 DOM1:映射文档的结构 DOM2: DOM视图,定义了跟踪不同文档视图的接口(例如CSS应用前后的文档) DOM事件,定义了事件和事件处理的接口 DOM样式,定义了基于CSS为元素应用样 ...
- (一)Tensorflow安装
主要包括下面两个指令: $ sudo apt-get install python-pip python-dev $ sudo pip install --upgrade https://storag ...
- SQL之case when then用法详解
case具有两种格式.简单case函数和case搜索函数. <span style="font-size:14px;">--简单case函数 case sex when ...
- spring学习 8-面试(事务,解决线程安全)
1.介绍一下Spring的事物管理 参考:Spring 学习7 -事务 2.Spring如何处理线程并发问题 Spring使用ThreadLocal解决线程安全问题 参考:Spring学习11- ...