zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #61 (Div. 2) D. Petya and His Friends 想法

    D. Petya and His Friends
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n.

    Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≤ i ≤ k) is evenly divisible by d. At that, we assume that all ai's are greater than zero.

    Knowing that Petya is keen on programming, his friends has agreed beforehand that the 1-st friend gives a1 sweets, the 2-nd one gives a2 sweets, ..., the n-th one gives an sweets. At the same time, for any i and j (1 ≤ i, j ≤ n) they want the GCD(ai, aj) not to be equal to 1. However, they also want the following condition to be satisfied: GCD(a1, a2, ..., an) = 1. One more: all the ai should be distinct.

    Help the friends to choose the suitable numbers a1, ..., an.

    Input

    The first line contains an integer n (2 ≤ n ≤ 50).

    Output

    If there is no answer, print "-1" without quotes. Otherwise print a set of n distinct positive numbers a1, a2, ..., an. Each line must contain one number. Each number must consist of not more than 100 digits, and must not contain any leading zeros. If there are several solutions to that problem, print any of them.

    Do not forget, please, that all of the following conditions must be true:

    • For every i and j (1 ≤ i, j ≤ n): GCD(ai, aj) ≠ 1
    • GCD(a1, a2, ..., an) = 1
    • For every i and j (1 ≤ i, j ≤ n, i ≠ j): ai ≠ aj

    Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

    Examples
    Input
    3
    Output
    99
    55
    11115
    Input
    4
    Output
    385
    360
    792
    8360
    题意:满足这三个条件,否则输出-1;
    • For every i and j (1 ≤ i, j ≤ n): GCD(ai, aj) ≠ 1
    • GCD(a1, a2, ..., an) = 1
    • For every i and j (1 ≤ i, j ≤ n, i ≠ j): ai ≠ aj

     思路:2显然-1;

        先找到一个3满足的条件,然后输出一个数的倍数即可;注意不要重复;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define esp 1e-13
    const int N=1e4+10,M=1e6+50000,inf=1e9+10,mod=1000000007;
    int main()
    {
        int x,y,i,z,t;
        scanf("%d",&x);
        if(x==2)
        printf("-1");
        else
        {
            printf("6
    10
    15
    ");
            for(int i=0,t=2;i<x-3;i++,t++)
            printf("%d
    ",6*t);
        }
        return 0;
    }

      

  • 相关阅读:
    钉钉内网穿透一键启动cmd脚本
    vscode的开发配置文件
    'scope' is defined but never used解决方法
    微信小程序使用echarts不跟随父元素滑动
    小程序图片开发工具能显示真机调试和体验版不显示
    Web端在线实时聊天,基于WebSocket(前后端分离)
    在vue项目中使用scss,以及vscode适配scss语法(解决使用scss语法编辑器报错)
    自动按需引入组件用不了(Vant)
    npm ERR! Unexpected end of JSON input while parsing near '...'解决方法
    div和img垂直居中的方法
  • 原文地址:https://www.cnblogs.com/jhz033/p/5767732.html
Copyright © 2011-2022 走看看