码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 20 C

时间:2017-05-01 21:02:45      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:color   viso   exist   pac   nal   test   res   turn   als   

Description

You are given positive integer number n. You should create such strictly increasing sequence of k positive numbersa1,?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.

Input

The first line consists of two numbers n and k (1?≤?n,?k?≤?1010).

Output

If the answer exists then 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分解成k个数的形式,要求他们的最大公约数最大

 解法:首先根据范围知道1e8后是无解的,然后根据等差数列和求是不是符合要求

再求出d的最大范围,接下来就是求最大的公约数了

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=654321;
ll n,num;
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>n>>num;
    ll sum=num*(num+1)/2;
    if(sum>n||num>(ll)1e8)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    ll d=n/sum;
    ll r=1;
   // cout<<d<<endl;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i) continue;
        if(i>=r&&i<=d) r=i;
        if(n/i>=r&&n/i<=d) r=n/i;
    }
    for(ll i=1;i<num;i++)
    {
        n-=i*r;
        cout<<i*r<<" ";
    }
    cout<<n<<endl;
    return 0;
}

 

 

 

Educational Codeforces Round 20 C

标签:color   viso   exist   pac   nal   test   res   turn   als   

原文地址:http://www.cnblogs.com/yinghualuowu/p/6792651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!