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:// ...
随机推荐
- angular2学习资源汇总
文档博客书籍类 官方网站: https://angular.io 中文站点: https://angular.cn Victor的blog(Victor是Angular路由模块的作者): https: ...
- KVC与KVO的不同
vc 就是一种通过字符串去间接操作对象属性的机制, 访问一个对象属性我们可以 person.age 也可以通过kvc的方式 [person valueForKey:@"age&quo ...
- IntelliJ IDEA字符串常量长度太长的问题解决:constant string too long
Java compiler下的Use compiler为Eclipse:
- C#测试程序运行时间
一.用C#自带的StopWatch函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 using System; usi ...
- Visual Studio 控制台应用程序 同时使用OpenCV和matlab mat文件操作
matalb具有灵活的图像处理,代码编写起来简洁而高效.而OpenCV具有很多成熟的计算机视觉算法,能够处理很多实时的识别处理等问题,而且代码运行起来效率很高.所以如何结合两者之间的优点,是让很多学术 ...
- win10 关键错误开始菜单和cortana无法工作 的问题
win10点击 '此电脑' 反键选择 管理 -服务和应用程序-服务 找到 User Manager 双击点击启动就行了 把 UserManager服务设为自动启动解决了
- shell中单引号、双引号、反引号的区别
'单引号' 忽略所有特殊字符 "双引号" 忽略大部分特殊字符,除了$ ` `反引号` 输出执行结果
- Dubbo超时重试机制带来的数据重复问题
Dubbo的超时重试机制为服务容错.服务稳定提供了比较好的框架支持,但是在一些比较特殊的网络环境下(网络传输慢,并发多)可能 由于服务响应慢,Dubbo自身的超时重试机制(服务端的处理时间超过了设定的 ...
- JS里取前天,昨天和今天
var today=new Date(); var yesterday=new Date(today.getTime()-1000*60*60*24); var thedaybeforeyesterd ...
- Qt Creator项目中使用qss
近期学习qt .使用的编译器是qt creator ,学习过程中遇到的题就是 怎样将程序中将要用到的.qss 文件静态编译到.exe程序中,而不是在程序执行时动态加载.动态加载的最大问题在于一旦.qs ...