赞
踩
题目大意:从1~n把这n个数分成两个集合,和为s1,s2,是否可以让这两个集合的gcd大于1(即不互质)
思路:稍加思考得知,只要不是1,2一定可以分成功,我是按照头尾相加的方式分的,类似等差数列的求和??
中间的一个或两个分一块,剩下的分一块,分一下奇偶就好啦
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- #include<iostream>
- #include<math.h>
- #include<queue>
- #include<string>
- #include<vector>
- #include<map>
- const int inf = 0x3f3f3f3f;
- using namespace std;
- const int N = 1e5+9;
- const int mod = 1e9+7;
- #define ll long long
- int n,k;
- int vis[29];
- int main()
- {
- //freopen("in.txt","r",stdin);
- scanf("%d",&n);
- if(n==1||n==2)
- {
- cout<<"No"<<endl;
- return 0;
- }
- cout<<"Yes"<<endl;
- if(n&1)
- { cout<<"1"<<" ";
- cout<<(n+1)/2<<endl;
- cout<<n-1;
- for(int i = 1; i<=n; i++)
- {
- if(i==(n+1)/2) continue;
- cout<<" "<<i;
- }
- cout<<endl;
- }
- else{
- cout<<2;
- cout<<" "<<n/2<<" "<<n/2+1<<endl;
- cout<<n-2;
- for(int i = 1; i<=n; i++)
- {
- if(i==n/2||i==(n/2+1)) continue;
- cout<<" "<<i;
- }
- cout<<endl;
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。