Codeforces 803C. Maximal GCD
题目链接:http://codeforces.com/contest/803/problem/C
中了若干trick之后才过...
k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这些数字增加的倍数x,使得序列变成${x,2x,3x...kx}$,然后再使最后一个数字变大满足要求就可以了,枚举的复杂度是根号$n$的。
要注意枚举倍数$x$的时候还要顺便枚举了$n/x$,然后${n*(n+1)/2}$这个东西是会爆long long的。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 10010
#define llg long long
#define LDB long double
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,cha,k; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} llg find(llg x)
{
llg up=sqrt(x),Ans=-;
for (llg i=;i<=up;i++)
if (x%i==)
{
if ((LDB)x*/(LDB)i/(LDB)k>=(LDB)(k+) && i>Ans) {Ans=i; cha=x/i-(k*(k+))/;}
if ((LDB)i*/(LDB)k>=(LDB)(k+) && x/i>Ans) {Ans=x/i; cha=i-(k*(k+))/;}
}
return Ans;
} int main()
{
yyj("C");
cin>>n>>k;
llg val=find(n);
if (val==-) {cout<<-; return ;}
for (llg i=;i<k;i++) printf("%lld ",i*val);
printf("%lld",(k+cha)*val);
return ;
}
Codeforces 803C. Maximal GCD的更多相关文章
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
- Codeforces 803C. Maximal GCD 二分
C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...
- CodeForces - 803C Maximal GCD 【构造】
You are given positive integer number n. You should create such strictly increasing sequence of k po ...
- Codeforces H. Maximal GCD(贪心)
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeFoorces 803C Maximal GCD
枚举. 枚举$gcd$,然后计算剩下的那个数能不能分成$k$个递增的数. #include <iostream> #include <cstdio> #include < ...
- 【数学】codeforces C. Maximal GCD
http://codeforces.com/contest/803/problem/C [题意] 给定两个数n,k(1 ≤ n, k ≤ 10^10) 要你输出k个数,满足以下条件: ①这k个数之和等 ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- Maximal GCD CodeForces - 803C (数论+思维优化)
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 ...
随机推荐
- Servlet学习1
1.首先在Tomcat的webapp目录下新建文件夹myWebapp,作为自己的web应用. 2.myWebapp下新建WEB-INF(必须这个名)目录,WEB-INF下新建classes目录放置se ...
- DAX/PowerBI系列 - 玩转阿里云 Alicloud Pricing
DAX/PowerBI系列 - 玩转 阿里云主机 Ali Cloud ECS 难度: ★★☆☆☆(1星) 适用范围: ★★★☆☆(3星) 欢迎交流与骚扰 这是啥: 双十一就到了,码农门,程序猿们有没有 ...
- IIS网站 由http协议改变为https协议
https://www.cnblogs.com/boosasliulin/p/6811231.html?utm_source=itdadao&utm_medium=referral
- MUI 返回顶部
//绑定滚动到顶部按钮事件 if ($("#scroll-up").length > 0) { var scrollToTopBox = $("#scroll-up ...
- navicat 远程访问mariadb失败,修改配置如下
1.首先配置允许访问的用户,采用授权的方式给用户权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '121212' WITH GRAN ...
- html5 css折叠导航栏
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- SpringCloud入门之应用程序上下文服务(Spring Cloud Context)详解
构建分布式系统非常复杂且容易出错.Spring Cloud为最常见的分布式系统模式提供了简单易用的编程模型,帮助开发人员构建弹性,可靠和协调的应用程序.Spring Cloud构建于Spring Bo ...
- nmon安装与使用
一.检查安装环境 1,# uname –a (查看操作系统信息,所检查服务器为64位操作系统) Linux jmeter 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 ...
- MyBatis探究-----动态SQL详解
1.if标签 接口中方法:public List<Employee> getEmpsByEmpProperties(Employee employee); XML中:where 1=1必不 ...
- MyBatis 处理sql中的 大于,小于,大于等于,小于等于
Mybatis中的sql语句中的 “<” 和 “>” 号要用转义字符 “<” 和 ”>“ ,否则会报错! 如查找年龄大于等于指定年龄的用户信息: SELEC ...