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. feedparser的安装

    Python中常常要利用RSS下载文本.由于这个Python开源软件嘛,碎片化特别严重.反正是各种边边角角的小问题.网上找来找去找半天都没解决如何安装.我的是win7的.python 是3.4版本的. ...

  2. PHP解决网站大流量与高并发

    1:硬件方面 普通的一个p4的服务器每天最多能支持大约10万左右的IP,如果访问量超过10W那么需要专用的服务器才能解决,如果硬件不给力 软件怎么优化都是于事无补的.主要影响服务器的速度 有:网络-硬 ...

  3. Deque 双端队列 Stack 堆栈

    1. peek 获取栈顶元素 pop   删除栈顶元素

  4. ABAP-container拆分

    1.界面 2.代码 *&---------------------------------------------------------------------* *& Report ...

  5. leetcode题解 candy

    要求的条件是: 1.每个人最少一个糖果. 2.相邻的小朋友,要保证,评分高的比评分低的糖果多. 如果从一侧扫描的话,容易确定的就是递增序列,只要上升1个就够了. 容易出现问题的就是:遇到下降期,或者相 ...

  6. jquery事件绑定与事件委托

    //事件绑定简写形式 $(".div2 button").click(function () { $(".div1").scrollTop(0) }) //写全 ...

  7. Java继承与多态浅析

    一.继承 1.通过extends继承的父类可以是不加abstract关键字的普通类,也可以是加了abstract关键字的抽象类.继承普通类时可以覆写父类的方法,或者创建自己独有的方法,或者这两     ...

  8. 跨域(六)——window.name

    window.name也可以进行跨域数据传输. 下面是相应的代码,evil.html跨域读取foo.html的数据,其中proxy.html和evil.html同域,没有任何内容. evil.html ...

  9. jquery Load方法的重要点

    一个非常重要而且很容易忽视的问题就是:你是否load进了你必须load的元素,是否有的没有load进来,打开firebug查看一下

  10. C++17尝鲜:结构化绑定声明(Structured Binding Declaration)

    结构化绑定声明 结构化绑定声明,是指在一次声明中同时引入多个变量,同时绑定初始化表达式的各个子对象的语法形式. 结构化绑定声明使用auto来声明多个变量,所有变量都必须用中括号括起来. cv-auto ...