hdu5902 GCD is Funny
来源:互联网 发布:vb有什么用 编辑:程序博客网 时间:2024/06/06 07:24
神坑巨坑,开始看题以为两两的最大公约数就对了,错了好多以后,重看了下英文题,原谅我的英语水平太高。
看着别人的解释看懂了,对两两最大公约数的产生的数也要加入,共进行n-2次
开始那一次找最大公约数算一次,接着再来n-3 次。哇哇哇,哇咔咔。
#include<iostream>#include<math.h>#include<cstdio>#include<cstring>using namespace std;const int maxn=510;int gcd(int a,int b)//最大公约数;{ return b==0?a:gcd(b,a%b);}bool b[1010];int main(){ int t; cin>>t; int n,a[501]; while(t--) { memset(b,0,sizeof(b)); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) b[gcd(a[i],a[j])]=1; int len=1; int flag=1; while(len<n-2&&flag) { flag=0; len++; for(int i=1;i<=1000;i++) if(b[i]) { for(int j=1;j<=n;j++) if(!b[gcd(i,a[j])]) {flag=1; b[gcd(i,a[j])]=1; } } } flag=0; for(int i=1;i<=1000;i++) { if(b[i])//公约数存在; { if(!flag) { flag=1; printf("%d",i); } else printf(" %d",i); } } cout<<endl; }}
0 0
- hdu5902 GCD is Funny
- hdu5902 GCD is Funny
- hdu5902 GCD is Funny
- hdu5902 GCD is Funny(错) && hdu5904 LCIS(最长公共连续上升子序列)
- GCD is Funny
- GCD is Funny (gcd + 想法)
- hdu 5902 GCD is Funny
- HDU 5902 GCD is Funny
- HDU-5902-GCD is Funny
- HDU 5902:GCD is Funny (GCD)
- HDU 5902 GCD is Funny(GCD)
- Hdu-5902-GCD is Funny (gcd)
- hdu 5902 GCD is Funny(BestCoder #87 1001)
- HDU5902
- hdu5902,5505——GCD小合集
- Mecanum wheels is funny
- hdu5902GCD is Funny+数论
- hdu5902暴力
- CoreText(七):图文混排
- Apache部署django项目
- apex 转义字符
- ecshop添加多国货币
- JAVA从菜鸟【入门】到新手【实习】一一语言学习(英语与语文)
- hdu5902 GCD is Funny
- 如何学习Linux
- js对象字面量
- docker 安装gitlab-ce下ssh无法使用原因
- 初学mysql(二)-数据库之表内容单表查询
- Days28 自定义Veiw(一)
- CentOS 安装 JDK
- vector所存储对象地址在vector操作过程中发生变化
- emacs 插件列表