C - Aladdin and the Flying Carpet 有多少种长方形满足面积为a(<=10^12),且最短边>=b;长方形边长为整数,且一定不可以是正方形。
- /**
- 题目:C - Aladdin and the Flying Carpet
- 链接:https://vjudge.net/contest/154246#problem/C
- 题意:有多少种长方形满足面积为a,且最短边>=b;长方形边长为整数,且一定不可以是正方形。
- 思路:求出a的素因子以及每个素因子的个数,然后搜索所有满足条件的方法数。
- 其实可以求出所有<b的方法数,用总的减去它,可以更快,不过更麻烦。
- */
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e6+;
- ll prime[maxn];
- int z;
- vector<ll>v;
- int num[];
- int cous;
- ll a, b;
- void init()
- {
- memset(prime, , sizeof prime);
- for(int i = ; i < maxn; i++){
- if(prime[i]==){
- for(int j = i+i; j < maxn; j+=i){
- prime[j] = ;
- }
- }
- }
- z = ;
- for(int i = ; i < maxn; i++){
- if(prime[i]==){
- prime[z++] = i;
- }
- }
- /// cout<<"prime number = "<<z<<endl; 78000ge
- }
- ll ans;
- void solve(int h,ll value)
- {
- if(h==){
- if(value>=b&&a/value>=b&&value*value!=a) ans++;
- return;
- }
- for(int i = ; i <= num[h-]; i++){
- if(i>){
- value*=v[h-];
- }
- solve(h-,value);
- }
- }
- int main()
- {
- init();
- int T, cas=;
- cin>>T;
- while(T--)
- {
- int cnt = ;
- scanf("%lld%lld",&a,&b);
- v.clear();
- ll n = a;
- cous = ;
- memset(num, , sizeof num);
- for(int i = ; i < z&&prime[i]*prime[i]<=n; i++){
- if(n%prime[i]==){
- v.push_back(prime[i]);
- while(n%prime[i]==){
- n/=prime[i];
- num[cous]++;
- }
- cous++;
- }
- }
- if(n>){
- v.push_back(n);
- num[cous++] = ;
- }
- ans = ;
- solve(cous,);
- printf("Case %d: %lld\n",cas++,ans/);
- }
- return ;
- }
C - Aladdin and the Flying Carpet 有多少种长方形满足面积为a(<=10^12),且最短边>=b;长方形边长为整数,且一定不可以是正方形。的更多相关文章
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理
题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet PDF (English) S ...
- Aladdin and the Flying Carpet
Aladdin and the Flying Carpet https://cn.vjudge.net/contest/288520#problem/C It's said that Aladdin ...
- Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...
- 数论 C - Aladdin and the Flying Carpet
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...
- E - Aladdin and the Flying Carpet
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...
- LightOJ 1341 Aladdin and the Flying Carpet 数学
题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...
- LightOJ1341 Aladdin and the Flying Carpet
题意 给一对数字 a,b ,a是一个长方形的面积,问有多少种整数的边的组合可以组成面积为a的长方形,要求最短的边不得小于b 数据组数T<=4000, a,b<=10^12 Solution ...
- [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))
题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...
随机推荐
- JS删除数组中某一项或几项的方法汇总
1.JS中的splice方法 splice(index, len, [item]) //注意:该方法会改变原始数组. splice有3个参数,它也可以用来替换/删除/添加数组内某一个或者几个值. ...
- CSS3:box-sizing 怪异盒模型
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Git -- git中本地与远程库的关联与取消
1.在本地目录下关联远程repository : git remote add origin git@github.com:git_username/repository_name.git 2.取消本 ...
- python socket timeout设置
需要在调用socket的connect方法之前设置settimeout(time)方法,另外在设置之后要将再次调用settimeout(None)来设置socket进入阻塞模式. 如下代码示例: so ...
- openstack学习笔记(一)-openstack的基础知识
一.OpenStack的基础知识 openstack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache2.0许可证(兼容GPLv3以及DFSG)授权的自由软件和 ...
- Spark Streaming on Kafka解析和安装实战
本课分2部分讲解: 第一部分,讲解Kafka的概念.架构和用例场景: 第二部分,讲解Kafka的安装和实战. 由于时间关系,今天的课程只讲到如何用官网的例子验证Kafka的安装是否成功.后续课程会接着 ...
- LVS负载均衡之NAT模式部署
1.LVS的NAT模式介绍 参考自官网:http://www.linuxvirtualserver.org/zh/lvs3.html 由于IPv4中IP地址空间的日益紧张和安全方面的原因,很多网络使用 ...
- CentOS 7 yum安装失败问题
在CentOS 7中,执行yum安装,一直报错,错误信息如下 其实在上述的错误信息中,上述中的repodata/repomd.xml文件据说是/mnt目录rpm包的目录,路径 在/mnt中因为没有/r ...
- Java中的值传递与“引用传递”
首先,Java没有 引用传递 这么一说. Java仅仅有值传递.传递的都是值,基本数据类型传递的是值.引用类型传递的是地址值. 我来理一下这当中宛如米线跟米面绞在一起了,再跟粉丝混在一起的关系. 好的 ...
- [Functional Programming 101] Crocks.js -- when to use map and when to use chain?
As a beginner of Crocks.js, it was a problem for we to figure out when to use .map() and when to use ...