Educational Codeforces Round 20 C

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;
}
复制代码

 

 

 

posted @   樱花落舞  阅读(222)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示