zoukankan      html  css  js  c++  java
  • 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
    output
    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.

    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
    暴力枚举,k个数都是n的因子
     n - s > (k - 1)·d.然后从d枚举到n/d就好了,这个思路我是想不到的,听打神讲的,然而我还写不出来,抄了大神的代码,CF这样很好啊。帮助小白进阶,从哪里开始枚举
    自己要想清楚
    #include <cstdio>
    typedef long long ll;
    int main()
    {
        ll n, k;
        scanf("%lld%lld", &n, &k);
        if (k > (ll)1e8)
        {
            printf("-1
    ");
            return 0;
        }
        ll b = n / (k * (k + 1) / 2);
        if (b == 0)
        {
            printf("-1
    ");
            return 0;
        }
        ll r = 1;
        for (ll x = 1; x * x <= n; x++)
        {
            if (n % x != 0) continue;
            if (x <= b && x > r) r = x;
            if (n / x <= b && n / x > r) r = n / x;
        }
        for (int i = 1; i < k; i++)
            printf("%lld ", r * i);
        n -= r * k * (k - 1) / 2;
        printf("%lld
    ", n);
    
        return 0;
    }
    View Code
  • 相关阅读:
    青松云安全-WAF-1.0.655 (ubuntu 14.04 server)
    相似变换和仿射变换
    参数坐标系统变换
    城市测量坐标系统的建立
    工程测量坐标系
    大地测量控制点坐标转换技术规范
    为什么样本方差(sample variance)的分母是 n-1?
    似大地水准面
    typedef的用法
    同一椭球面经纬度坐标与空间直角坐标之间的相互转换
  • 原文地址:https://www.cnblogs.com/BobHuang/p/6799181.html
Copyright © 2011-2022 走看看