codeforces 66D D. Petya and His Friends( 数论+构造)
来源:互联网 发布:手机qq变声软件 编辑:程序博客网 时间:2024/05/18 03:57
题目链接:
codeforces 66D
题目大意:
要求构造出一个满足下列条件的数列:
题目分析:
- 首先筛出100个素数
- 然后先给这n个数每人一个素数(不同的)
- 然后为了保证他们每两个之间的gcd都不等于1,那么我们找出6个素数(不同且没有用过的),然后将原数列分成四段,两两组合,组合在一起的用一个素数乘上去刷一遍,刷完之后依旧能够保证整个数列的gcd是1.
- 注意3因为不够4个,所以要特判,2不能构造,也要特判。
AC代码:
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <vector>#define MAX 1007using namespace std;typedef long long LL;int n;int mark[MAX];int ans[MAX];vector<int> v;void init (){ memset ( mark , -1 , sizeof ( mark )); for ( int i = 2 ; i < MAX ; i++ ) { if ( ~mark[i] ) continue; if ( i != 2 && i != 3 && i != 5 && i != 7 && i != 11 && i != 13 ) v.push_back ( i ); for ( int j = 2*i ; j < MAX ; j += i ) mark[j] = i; }}int gcd ( int a , int b ){ return !b?a:gcd(b,a%b);}int main ( ){ init (); while ( ~scanf ("%d" , &n ) ) { if ( n == 2 ) { puts ( "-1" ); continue; } if ( n == 3 ) { puts ( "99\n55\n11115"); continue; } for ( int i = 0 ; i < n ; i++ ) ans[i] = v[i]; for ( int i = 0 ; i < n/2 ; i++ ) ans[i] *= 2; for ( int i = n/2 ; i < n ; i++ ) ans[i] *= 3; for ( int i = 0 ; i < n/4 ; i++ ) ans[i] *= 5; for ( int i = n/4*3 ; i < n ; i++ ) ans[i] *= 5; for ( int i = n/4 ; i < n/4*3 ; i++ ) ans[i] *= 7; for ( int i = 0 ; i < n/4 ; i++ ) ans[i] *= 11; for ( int i = n/2 ; i < n/4*3 ; i++ ) ans[i] *= 11; for ( int i = n/4 ; i < n/2 ; i++ ) ans[i] *= 13; for ( int i = n/4*3 ; i < n ; i++ ) ans[i] *= 13; for ( int i = 0 ; i < n ; i++ ) printf ( "%d\n" , ans[i] ); }}
0 0
- codeforces 66D D. Petya and His Friends( 数论+构造)
- codeforces 66 D. Petya and His Friends(数论)
- CodeForces 66 D.Petya and His Friends(构造+数论+高精度)
- CodeForces 66D - 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 819D R #421 D.Mister B and Astronomers & 516E R #292 E. 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 689D-Friends and Subsequences
- CodeForces 689D-Friends and Subsequences
- Codeforces 689D Friends and Subsequences
- 【22.48%】【codeforces 689D】Friends and Subsequences
- CodeForces 112D Petya and Divisors 模拟题(水
- CodeForces 584D - Dima and Lisa(数论)
- QT界面,按钮,Label背景图片设置方法
- zoj 3885 The Exchange of Items 最小费用最大流
- BZOJ1050
- python 之 utf-8编码的秘密
- 离线语音听写
- codeforces 66D D. Petya and His Friends( 数论+构造)
- Hadoop DistributedCache的使用解释
- sepFilter2D函数
- AsyncTask介绍
- Centos下pure-ftpd安装配置详解
- strcpy手写代码
- ZOJ 3347 Picture Handling
- js获得子页面元素
- MFC COMBOBOX的使用