Aladdin and the Flying Carpet

https://cn.vjudge.net/contest/288520#problem/C

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.

Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin's uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.

Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there can be two types of carpets and their sides are: {2, 6} and {3, 4}.

Input

Input starts with an integer T (≤ 4000), denoting the number of test cases.

Each case starts with a line containing two integers: a b (1 ≤ b ≤ a ≤ 1012) where a 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

唯一分解定理

当tmp>1时,根据它的因子是1,所以要乘上(1+1)(这是我的理解方法。。。有错的话麻烦各位大佬指出

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int phi[maxn];
bool vis[maxn];
int prime[maxn];
int tot; void Init(int n){
phi[]=;
for(int i=;i<=n;i++){
if(!vis[i]){
prime[++tot]=i;
phi[i]=i-;
}
for(int j=;j<=tot&&i*prime[j]<=n;j++){
vis[i*prime[j]]=true;
if(i%prime[j]==){
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int t;
Init(maxn-);
cin>>t;
for(int _=;_<=t;_++){
ll a,b; cin>>a>>b;
ll tmp=a;
ll ans=;
if(a<b*b){
cout<<"Case "<<_<<": "<<<<endl;
continue;
}
for(ll i=;i<=tot&&prime[i]*prime[i]<=tmp;i++){
if(tmp%prime[i]==){
ll co=;
while(tmp%prime[i]==){
co++;
tmp/=prime[i];
}
co++;
ans*=co;
}
}
if(tmp>) ans*=(+);
ans/=;
for(ll i=;i<b;i++){
if(a%i==) ans--;
}
cout<<"Case "<<_<<": "<<ans<<endl; } }

Aladdin and the Flying Carpet的更多相关文章

  1. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  2. C - Aladdin and the Flying Carpet 有多少种长方形满足面积为a(<=10^12),且最短边>=b;长方形边长为整数,且一定不可以是正方形。

    /** 题目:C - Aladdin and the Flying Carpet 链接:https://vjudge.net/contest/154246#problem/C 题意:有多少种长方形满足 ...

  3. LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理

    题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet    PDF (English) S ...

  4. Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】

    Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...

  5. 数论 C - Aladdin and the Flying Carpet

    It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...

  6. E - Aladdin and the Flying Carpet

    It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...

  7. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

  8. 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...

  9. LightOJ 1341 Aladdin and the Flying Carpet 数学

    题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...

随机推荐

  1. ubuntu16.04搭建geodjango+postgresql+postgis的WebGIS框架(三)加载空间数据

    之前两篇基本上搭好了geodjango开发的环境了,当然你的电脑上肯定要有python和django的环境(这个我就不介绍了,网上一搜一大堆),我自己用的python3.5和django2.0(毕竟2 ...

  2. day04-完整性约束

    完整性约束 关键字: not null 与 default unique primary auto_increment foreign key 1.介绍 约束条件与数据类型的宽度一样,都是可选参数作用 ...

  3. UI5-学习篇-9-本地Eclipse UI5应用发布到SAP前端服务器

    参考路径: https://blogs.sap.com/2017/11/19/sap-fiori-ui5-application-deployment/ 1.准备环境 2.上载SAP-FIORI前端服 ...

  4. 页面中href链接的碰撞

    问题: 如上图动态生成一个li列表,点击之后页面直接全部刷新了一遍 原因: 动态生成的代码(第一个图)中href链接地址与顶部页面(上图)中固定的href链接存在冲突 如果动态生成的列表指定的链接名称 ...

  5. golang使用Nsq(转)

    为什么要使用Nsq 最近一直在寻找一个高性能,高可用的消息队列做内部服务之间的通讯.一开始想到用zeromq,但在查找资料的过程中,意外的发现了Nsq这个由golang开发的消息队列,毕竟是golan ...

  6. How to Pronounce the Idiom: ‘Out Like a Light’

    How to Pronounce the Idiom: ‘Out Like a Light’ Share Tweet Share Tagged With: Idioms English is full ...

  7. t959 unknown device 解决办法

    换机器没用 换数据线没用 最后装了Kies3,好了! -------- 更新 跟数据线也有关系 换一条三星自带的试试

  8. [jQ/PHP]使用JS数组储值的两种情况(提交PHP处理)

    ---------------------------------------------------------------------------------------------------- ...

  9. Android Studio 上传GitHub项目失败后的一些问题

    在Android Studio上传项目到GitHub时候多上传了了一些项目,想删除,但是报诸如 Remote project is already on GitHub 一些乱七八糟的问题,而且,提示p ...

  10. idea中pom文件需要添加的依赖

    <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉. --> <!-- IDEA的maven项目中,默认源代码目录下的xml等资源文件并不会在编译的时候一块 ...