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;
}
时间: 2024-10-04 09:49:04

Educational Codeforces Round 20 C的相关文章

Educational Codeforces Round 20 C(math)

題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的gcd盡量大... 思路: 顯然題目的要求是求 n = a1*cnt + a2*cnt + a3*cnt..+ak*cnt 其中a1<a2<a3..<ak 並且要求cnt盡量大: 要使cnt盡量大,那麼顯然a1...ak要盡量小, 那麼可以令a1...ak=1, 2, 3, ..k, 令key

Educational Codeforces Round 20 B

Description You are given the array of integer numbers a0,?a1,?...,?an?-?1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. Input The first line cont

Educational Codeforces Round 20 A

Description You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the botto

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 should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words

Educational Codeforces Round 20 A. Maximal Binary Matrix(模拟)

题意:给你一个n*n的全是0的矩阵,和k个数字"1",让你把这k个数字1按照从上到下,从左到右的顺序构建出来 思路:模拟即可 代码: #include <iostream> #include <cstring> using namespace std; int main() { int n,k; int data[105][105]; while(cin>>n>>k) { memset(data,0,sizeof(data)); if(k

Educational Codeforces Round 20解(bu)题记录

A. Maximal Binary Matrix 解法:暴力模拟+贪心 #include<bits/stdc++.h> using namespace std; int a[110][110]; int main(){ int n,k,cmp,f=0;scanf("%d%d",&n,&k); if(k>n*n){puts("-1");return 0;}cmp=n; int r=1; while(k>=2*cmp-1){ k-

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Educational Codeforces Round 26 D. Round Subset(dp)

题目链接:Educational Codeforces Round 26 D. Round Subset 题意: 给你n个数,让你选其中的k个数,使得这k个数的乘积的末尾的0的个数最大. 题解: 显然,末尾乘积0的个数和因子2和因子5的个数有关. 然后考虑dp[i][j]表示选i个数,当前因子5的个数为j时,能得到因子2最多的为多少. 那么对于每个数,记录一下因子2和5的个数,做一些01背包就行了. 1 #include<bits/stdc++.h> 2 #define mst(a,b) me

CodeForces 837F - Prefix Sums | Educational Codeforces Round 26

按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforces Round 26 题意: 设定数组 y = f(x) 使得 y[i] = sum(x[j]) (0 <= j < i) 求初始数组 A0 经过多少次 f(x) 后 会有一个元素 大于 k 分析: 考虑 A0 = {1, 0, 0, 0} A1 = {1, 1, 1, 1} -> {C(