UVa-10139 Factovisors -(阶乘的整除)
来源:互联网 发布:网络教育与自考哪个好 编辑:程序博客网 时间:2024/05/17 07:04
计算数 m 和数 2 ~n 的 GCD,若 GCD > 1,则 m /= GCD,若最后 m 不为 1 则表明 m 不能整除 n!,
代码:
#include<iostream>#include<string>#include<cstdio>#include<algorithm>#include<cmath>#include<iomanip>#include<queue>#include<cstring>#include<map>using namespace std;#define M 1000005typedef long long ll;int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}bool isprime(int x){ double tx=sqrt(1.0*x); int it=2; while(it<=tx&&x%it!=0) it++; if(it>tx) return true; else return false;}/*bool isprime(int number){ if (number == 2) return true; if (number % 2 == 0) return false; for (int c = 3; c <= ceil(sqrt(1.0*number)); c += 2) if (number % c == 0) return false; return true;}*/int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { if(m==0) { printf("%d does not divide %d!\n",m,n); continue; } if(m==1) { printf("%d divides %d!\n",m,n); continue; } if(isprime(m)&&m>n) { printf("%d does not divide %d!\n",m,n); continue; } if(m<=n) { printf("%d divides %d!\n",m,n); continue; } bool flag=false; int tm=m; int gc; for(int i=n;i>=2;i--) { gc=gcd(tm,i); if(gc>1) { tm=tm/gc; if(tm<i) { flag=true; break; } if(isprime(tm)) { break; } } } if(flag) printf("%d divides %d!\n",m,n); else printf("%d does not divide %d!\n",m,n); } return 0;}
阅读全文
0 0
- UVa-10139 Factovisors -(阶乘的整除)
- UVa Problem 10139 Factovisors (阶乘与整除)
- UVa 10139 Factovisors (阶乘能否整除?)
- UVA 10139 Factovisors(数论)
- UVA 10139 判断n的阶乘能否被m整除
- uva 10139 求n的阶乘能否整除m
- UVa 10139 Factovisors
- uva 10139 factovisors
- Uva 10139 Factovisors
- UVa 10139 Factovisors
- UVa 10139 - Factovisors
- UVa 10139 - Factovisors
- UVA 10139 Factovisors
- UVa Problem Solution: 10139 - Factovisors
- 【 UVa 10139】 Factovisors 【 m | n!? 】
- PC/UVa 题号: 110704/10139 Factovisors
- 阶乘与整除
- 阶乘与整除
- 【智能商务】CRM+预测性分析,全程与客户接触的最佳方式
- 【JS】使用原型对象封装下拉框
- 条款02:尽量以const,enum,inline替换#define
- Linux下mysql出错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- 【人工智能】IBM商业价值研究院:认知中国-描绘中国人工智能发展蓝图
- UVa-10139 Factovisors -(阶乘的整除)
- 【财富空间】纽约创业如何追赶硅谷?看这个废弃的海军造船厂就可以
- Mysql hash和Btree索引的区别以及索引的建立规则
- 网口扫盲一:网卡初步认识
- ExpandableListView 二级列表
- 【智能零售】数据如何驱动新零售:线上单月 1.2 亿背后的数据化运营
- react-native 生成的android 及IOS 对应图标修改地址
- 使用关系型数据库分块处理几亿几十亿条数据
- 随机算法mt19937