Light OJ Aladdin and the Flying Carpet(约数个数)
来源:互联网 发布:琉璃神社换的域名2017 编辑:程序博客网 时间:2024/06/06 05:54
Input
Input starts with an integer T (≤ 4000), denoting the number of test cases.
Each case starts with a line containing two integers: ab(1 ≤ b ≤ a ≤ 1012) wherea denotes the area of the carpet and b denotes the minimum possible side of the carpet.
Output
For each case, print the case number and the number of possible carpets.
Sample Input
2
10 2
12 2
Sample Output
Case 1: 1
Case 2: 2
大致题意:有T(<=4000)组数据,求面积是a且边长均不小于b的矩形个数
思路:直接枚举b至sqrt(a)的约数分数会超时,然而先求出总的约数个数/2(成对出现)再减去小于b的所有约数即可(说明b是总体偏小的)
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const ll MAXN = 1e6+1000;bool vis[MAXN];ll prime[MAXN];int main(){ int cnt=0; for(int i=2;i*i<MAXN;i++) if(!vis[i]) for(int j=i*i;j<MAXN;j+=i) vis[j]=1; for(int i=2;i<MAXN;i++) if(!vis[i]) prime[cnt++]=i; int T; scanf("%d",&T); for(int cas=1;cas<=T;cas++) { int ans=0; ll s,lim; cin>>s>>lim; ll tmp=s; if(s>lim*lim) { ans=1; for(int i=0;prime[i]*prime[i]<=s;i++) { if(s%prime[i]) continue; int tmp=0; while(s%prime[i]==0) { tmp++; s/=prime[i]; } ans*=(tmp+1); } if(s>1) ans*=2; ans>>=1; for(int i=1;i<lim;i++) if(tmp%i==0) ans--; } cout<<"Case "<<cas<<": "<<ans<<endl; } return 0;}
0 0
- Light OJ Aladdin and the Flying Carpet(约数个数)
- LightOJ1341 Aladdin and the Flying Carpet 约数的个数
- Light OJ 1341 Aladdin and the Flying Carpet
- light oj 1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet Light OJ 1341
- LightOj 1341 Aladdin and the Flying Carpet (素数筛+求一个数的约数个数)
- Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS
- Light OJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
- [整数分解+dfs] light oj 1341 Aladdin and the Flying Carpet
- Light OJ 1341 Aladdin and the Flying Carpet(算数基本定理)
- Light OJ 1341 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
- Dancing Link基础题2
- 参加蓝桥杯感受
- https://leetcode.com/problems/string-to-integer-atoi/
- shell脚本if case for while语句小例子
- 根文件系统的制作
- Light OJ Aladdin and the Flying Carpet(约数个数)
- Android中Service的意义及用法
- 第一次写——ACM
- 【Linux】在Ubuntu中安装Eclipse与Helloworld
- Material Design Style Widget(二)──MaterialRadioButton(续)
- Java实现重构二叉树
- LeetCode Maximal Rectangle
- 第六周上机实践项目1——深复制体验(1)
- Android 程序框架设计