Aladdin and the Flying Carpet
来源:互联网 发布:行而知天下 编辑:程序博客网 时间:2024/05/23 01:28
题目意思:给你一个整数a和整数b 然后你需要求出存在多少个c*d=a (c!=d) min(c,d)>=b的组合数量 输出个数就好了。
如果直接循环遍历的话会超时。
然后就是利用唯一分解定理。
筛素数表
之前想说找出大于b的最小a因子 感觉除了搜索的话,然后使用(i+1)直接算 在分解的时候实现麻烦。
然后就是 算出总的因子数/2,然后减去小于b的。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;typedef long long ll;const ll maxn=1e6+5;ll predictprimenum(ll x){ return (ll)(x/log(x));}int prime[maxn],status[maxn];int len;void pri(){ len=0; memset(status,0,sizeof(status)); for(int i=2; i<=maxn; i++) { if(!status[i]) { prime[len++]=i; for(int j=i; j<=maxn; j+=i) status[j]=1; } }}int main(){ pri(); int t; scanf("%d",&t); for(int k=1; k<=t; k++) { ll a,b,en; scanf("%lld%lld",&a,&b); en=sqrt(a); int ans=1; ll c,num1=a; if(b*b>a) ans=0; else { for(int j=0; num1>1&&j<len; j++) { int i=0; while(num1%prime[j]==0) { i++; num1/=prime[j]; } ans*=(i+1); } if(num1>1) ans*=2;///a本身为质数 超越了素数表里面的额数 ///且只能有一个 假若有两个的话 值就会超过1E12 ans>>=1; for(int j=1;j<b;j++) if(a%j==0) ans--; } printf("Case %d: %d\n",k,ans); } return 0;}
0 0
- Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet
- lightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1341Aladdin and the Flying Carpet
- LightOJ 1341 - Aladdin and the Flying Carpet
- LightOJ1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet [整数分解]
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- LightOJ 1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- LightOJ-1314 Aladdin and the Flying Carpet
- Light OJ Aladdin and the Flying Carpet(约数个数)
- LightOJ 1341 - Aladdin and the Flying Carpet【合数分解】
- GRE写作必备句型
- sublime text2 插件 zencoding的安装及使用
- 日志管理--log4j
- POJ 1008 Maya Calendar
- backtrace&&backtrace_symbols 查找段错误 打印堆栈信息
- Aladdin and the Flying Carpet
- HDU 2032 杨辉三角
- C++ 调用字体框和调色板的代码
- Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide五大Android开源组件加载网络图片的优缺点比较
- COPY 深入理解Java内存模型
- gem source更改为淘宝,bundle install时报错,如何解决?
- POJ 3273 Monthly Expense
- testng 教程之使用参数的一些技巧配合使用reportng
- 第一篇博客