Codeforces 66 D Petya and His Friends(找规律)

Codeforces 66 D Petya and His Friends

链接:http://codeforces.com/problemset/problem/66/D


题目

Time Limit:2000MS Memory Limit:262144KB
Description
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).

Sample Input
3
Sample Output
99
55
11115

Sample Input
4
Sample Output
385
360
792
8360


题意

给你一个数n。让你输出n个数,保证任意两个的公约数不为1。同时保证所有数的公约数为1。


分析

首先,样例这种东西很有迷惑性。
仔细想一下就发现了规律,只要保证前三个互相有不同的素因子(比如2、3、5),后面的按倍数放大即可。


源码

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
#define mem0(x) memset(x,0,sizeof x)
#define mem1(x) memset(x,1,sizeof x)
#define mem11(x) memset(x,-1,sizeof x)
#define dbug cout<<"here"<<endl;
//#define debug

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x7fffffff;
const int MAXN = 1e6+10;
const int MOD = 1000000007;

int main(){
    #ifdef debug
        freopen("C:\Users\asus-z\Desktop\input.txt","r",stdin);
        freopen("C:\Users\asus-z\Desktop\output.txt","w",stdout);
    #endif
    int n;
    cin >> n;
    int a[3] = {10,6,15};
    if(n<=2)
        cout << "-1" << endl;
    else{
        for(int i = 0; i < 3; ++i){
            cout << a[i] << endl;
        }
        for(int i = 3; i <= n-1; ++i){
            cout << 6*i << endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值