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. ActiveMQ 学习

    链接:  http://www.cnblogs.com/zhuxiaojie/p/5564187.html#autoid-1-0-0

  2. babel 基本

    babel的大概知识点 . babel常用的转译器是babel-preset-env. 常用的配置选项是plugins和presets 常用的使用场景是在webpack中 https://www.cn ...

  3. netty为啥要二次开发

    很早之前就看过李林峰写的netty的书,但是感觉没有直接用到还是理解不够深入,现在的公司有两套自己基于Netty开发的系统,感觉才真正理解为啥要这么做 借用别人文章回顾下 https://www.cn ...

  4. EMQ笔记

    飞行窗口(Inflight Window)保存当前正在发送未确认的Qos1/2消息.窗口值越大,吞吐越高:窗口值越小,消息顺序越严格. 当客户端离线或者飞行窗口(Inflight Window)满时, ...

  5. shell编程:基本语法

    要掌握一门语言,就要先掌握它的语法.如同C语言一般,shell也有自己的语法. 变量 按照惯例,Shell变量通常由字母加下划线开头,由任意长度的字母.数字.下划线组成.有两种类型的Shell变量: ...

  6. Python调用外部系统命令

    利用Python调用外部系统命令的方法可以提高编码效率.调用外部系统命令完成后可以通过获取命令执行返回结果码.执行的输出结果进行进一步的处理.本文主要描述Python常见的调用外部系统命令的方法,包括 ...

  7. TCP/IP网络协议的通俗理解,SOCKET,HTTP,SOAP

    TCP/IP,HTTP,SOAP等协议之区别   术语TCP/IP代表传输控制协议/网际协议,指的是一系列协议.“IP”代表网际协议,TCP和UDP使用该协议从一个网络传送数据包到另一个网络.把IP想 ...

  8. eclipse git 拉取内容

  9. java中Integer和int的区别(转)

    int和Integer的区别 1.Integer是int的包装类,int则是java的一种基本数据类型 2.Integer变量必须实例化后才能使用,而int变量不需要 3.Integer实际是对象的引 ...

  10. Keil 报错汇总

    main.c(6): warning:  #1-D: last line of file ends without a newline 解决:main.c 最后一行加回车就可以了. keil中文注释出 ...