CodeForces 66D - Petya and His Friends(构造)
来源:互联网 发布:2017党章党规网络答题 编辑:程序博客网 时间:2024/05/21 10:44
D. Petya and His Friends
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
题意:
给出n个数,让你构造他们,使得两两之间的gcd不等于1,同时整体的gcd等于1,如果不能构造,输出-1.
解题思路:
如果是2就必然无法构造。
对于n大于2的情况,先让n个数都为1,然后除了第一个都乘上2,除了第二个都乘上3,再让第一个和第二个都乘上5,最后让n个数都乘上没有出现过的素数即可。
这样首先让除了第一个的所有数gcd都为2,再让除了2的所有数gcd都为3,再使得1和2非互素。最后处理,使得每个数都不相同即可。
AC代码:
#include<bits/stdc++.h>using namespace std;int a[1005];int main(){ int n; scanf("%d",&n); for(int i = 0;i < n;i++) scanf("%d",&a[i]); int res = 0; for(int i = 0;i < n;i++) { int cnt = 1; int l = i-1,r = i+1; while(a[l] <= a[l+1]&&l >= 0) l--,cnt++; while(a[r] <= a[r-1]&&r < n) r++,cnt++; res = max(res,cnt); } printf("%d\n",res); return 0;}
- codeforces 66D D. Petya and His Friends( 数论+构造)
- CodeForces 66D - Petya and His Friends(构造)
- CodeForces 66 D.Petya and His Friends(构造+数论+高精度)
- codeforces 66 D. Petya and His Friends(数论)
- Codeforces 66 D Petya and His Friends(找规律)
- CF 66D Petya and His Friends
- CF 61 div2 D. Petya and His Friends
- CodeForces - 515B Drazil and His Happy Friends
- codeforces 515B B. Drazil and His Happy Friends(模拟)
- codeforces#292B_Drazil and His Happy Friends-暴力水题
- [数论] Codeforces 516E. Drazil and His Happy Friends
- Codeforces 439D Devu and his Brother
- Codeforces 439D Devu and his Brother
- CodeForces 439D Devu and his Brother
- [数论] Codeforces 819D R #421 D.Mister B and Astronomers & 516E R #292 E. Drazil and His Happy Friends
- CodeForces 689D-Friends and Subsequences
- CodeForces 689D-Friends and Subsequences
- Codeforces 689D Friends and Subsequences
- PHP 汉字转拼音
- css标签及其作用
- xml的布局中listview覆盖了circleview
- python错误 unicodedecodeerror ascii codec can’t decode byte 0xd7 in position 9 ordinal not in range(12
- http://www.jianshu.com/p/6a720e53e75a 全民TV
- CodeForces 66D - Petya and His Friends(构造)
- iOS 应用之间相互跳转URL Schemes
- 数组排序——选择法
- No module named yum错误的解决办法
- 百度阿里腾讯等各大公司内部java代码规范。
- java动态生成HTML文件
- Lua中的基本函数库
- Major GC和Full GC的区别
- Ubuntu下重新安装软件 配置文件不重新生成得问题解决