LightOJ1341 Aladdin and the Flying Carpet 约数的个数
来源:互联网 发布:php读取access数据库 编辑:程序博客网 时间:2024/06/07 14:25
- 利用素因子分解可以求出来共有多少个约数。
- 给的数据不可能双向卡,所以在此题中要么卡枚举1~b,要么卡b~a,从出题的角度选择了后者,所以要利用素因子分解先求出所有的1~a,再减去1~b,当然,最佳的办法是通过素因子分解的结果去枚举小于b的值,但操作更加复杂。
题目链接:http://acm.hust.edu.cn/vjudge/problem/27049
题意:给定a,b,1<=b<=a<=10^12,求b~a之间的a的约数对的个数
#include<cstdio>#include<iostream>#include<sstream>#include<cstdlib>#include<cmath>#include<cctype>#include<string>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<set>#include<map>#include<ctime>#include<vector>#include<fstream>#include<list>using namespace std;#define ms(s) memset(s,0,sizeof(s))typedef unsigned long long ULL;typedef long long LL;const int INF = 0x3fffffff;const int N = 1000000;bool primeTable[N+5];vector<int> p;void make_primeTable(){ fill(primeTable,primeTable+N,1); primeTable[0] = false; primeTable[1] = false; int maxed = sqrt(N); for(int i = 2; i <= maxed; ++i){ if(primeTable[i] == true){ p.push_back(i); for(int j = i*i; j <= N; j += i) primeTable[j] = false; } } for(int i = maxed+1; i <= N; ++i) if(primeTable[i] == true) p.push_back(i);}LL add_factor(LL n){ if(n == 1) return 0; LL s = 1; for(int i = 0, j = p.size(); i < j; ++i){ LL k = 0; while(n%p[i] == 0){ k++; n /= p[i]; } s *= (k+1); if(n == 1) break; } if(n > 1) s *= 2; s /= 2; return s;}int main(){// freopen("F:\\input.txt","r",stdin);// freopen("F:\\output.txt","w",stdout);// ios::sync_with_stdio(false); make_primeTable(); int t; long long a,b,m; long long ans; scanf("%d",&t); for(int k = 1; k <= t; ++k){ ans = 0; scanf("%lld%lld",&a,&b); m = sqrt(a); if(b > m) printf("Case %d: 0\n",k); else{ ans = add_factor(a); for(int i = 1; i < b; ++i){ if(a%i == 0) ans--; } printf("Case %d: %lld\n",k,ans); } } return 0;}
0 0
- LightOJ1341 Aladdin and the Flying Carpet 约数的个数
- LightOJ1341 Aladdin and the Flying Carpet
- Light OJ Aladdin and the Flying Carpet(约数个数)
- lightOJ1341 Aladdin 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
- 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
- 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
- 【数据结构】B树和B+树讲解
- spring,hiberante之*** is not valid without active transaction
- Go语言之环境搭建
- java线程同步volatile与synchronized
- UVA10878 - Decode the tape
- LightOJ1341 Aladdin and the Flying Carpet 约数的个数
- codeforces 710D Two Arithmetic Progressions
- NSRange、NSSize、NSPoint、NSRect
- c++文件io操作练习之写日志文件和读取参数配置文件
- 【3】windowNoTitle 和 android:windowNoTitle的区别
- 谈谈 Redis3.0 的集群处理
- 【机器学习】求解过程快速又简单的最小二乘支持向量机LSSVM二分类
- 基于Java中的简单验证码设计
- UIView的透明属性hidden、alpha、opaque