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

题目大意 就是给你一个面积N和一个可能的最小边m,问你满足条件的组合有多少个(不能是正方形)

题解:先求出a的因子的个数,然后暴力求出小与b而且是a的因子的个数,然后再减去就行了。对于这个题,边的最小值为b,所以如果b*b>=a的话,那么一定无解。若有解那么b<=sqrt(a)所以b的范围要小于1e6,但是t的范围是4e3,时间复杂度大约是o(bt)=4e10。明显不行.....,但是百度上都这么做的,可能是数据有点水吧~。

using namespace std;
typedef long long ll;
const ll N=1e6+;
const ll MAX=1e6+;
bool primes[N];
ll pre[N];
ll pos=;
void inint(){
primes[]=;
primes[]=;
for(ll i=;i<=MAX;i++){
if(!primes[i]) pre[++pos]=i;
for(ll j=;j<=pos&&i*pre[j]<=MAX;j++){
primes[i*pre[j]]=;
if(i%pre[j]==) break;
}
}
}
void solve(ll time){
ll a,b;
scanf("%lld%lld",&a,&b);
ll m=a;
if(b*b>=a) {
printf("Case %d: 0\n",time);
return ;
}
ll ans=;
for(ll i=;i<=pos;i++){
if(pre[i]>a) break;
if(a%pre[i]==){
ll p=;
while(a%pre[i]==) {
a/=pre[i];p++;
}
ans*=((ll)+p);
}
}
if(a!=) ans*=(ll);
ans/=(ll);
for(ll i=;i<b;i++) if(m%i==) ans--;
printf("Case %d: %lld\n",time,ans);
}
int main(){
int t;
inint();
scanf("%d",&t);
for(int i=;i<=t;i++) solve(i);
return ;
}

E - 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. Aladdin and the Flying Carpet

    Aladdin and the Flying Carpet https://cn.vjudge.net/contest/288520#problem/C It's said that Aladdin ...

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

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

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

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

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

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

  6. 数论 C - 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. Contest 157

    2019-10-06 12:15:28 总体感受:总体难度一般,dfs和dp题花了点时间,最后一题dp有思路,但是实现上不够好. 注意点:首先是hard问题的覆盖度依然是很大的问题,其次是要注意审题. ...

  2. Java的集合框架综述

    集合 用于存储和管理数据的实体被称为数据结构(data structure).数据结构可用于实现具有不同特性的集合对象,这里所说的集合对象可以看作一类用于存储数据的特殊对象. 集合内部可以采用某种数据 ...

  3. 【笔记3-27】Python语言基础

    流程控制语句 if语句 input() if-else if-elif-else

  4. 044.集群存储-StorageClass

    一 StoragClass 1.1 StorageClass概述 StorageClass作为对存储资源的抽象定义,对用户设置的PVC申请屏蔽后端存储的细节,一方面减少了用户对于存储资源细节的关注,另 ...

  5. ClickHouse学习系列之二【用户权限管理】

    背景 最近花了些时间看了下ClickHouse文档,发现它在OLAP方面表现很优异,而且相对也比较轻量和简单,所以准备入门了解下该数据库系统.在安装完之后首先做的应该如何设置用户密码以及权限控制.因为 ...

  6. 使用tensorflow的softmax进行mnist识别

    tensorflow真是方便,看来深度学习需要怎么使用框架.如何建模- ''' softmax classifier for mnist created on 2019.9.28 author: vi ...

  7. mongodb服务器启动

    以配置文件启动服务器: mongod --config /usr/local/mongodata/config/mongodb.conf(配置文件路径) 客户端启动: mango 关闭mongodb的 ...

  8. [noip模拟]画展<队列的基础知识>

    Description 博览馆正在展出由世上最佳的M位画家所画的图画.人们想到博览馆去看这几位大师的作品.可是,那里的博览馆有一个很奇怪的规定,就是在购买门票时必须说明两个数字,a和b,代表要看展览中 ...

  9. 针对Kafka的centos系统参数优化

    TCP网络优化 sudo vim /etc/sysctl.conf vm.max_map_count=655360net.core.rmem_default=262144net.core.rmem_m ...

  10. Lisp-01: 相关开发环境配置部署

    Common Lisp 学习笔记系列01 要学一门编程语言,首先需要将语言的环境配置好.如果想要个直接上手的环境,感谢日本的大神 Shirakumo,打造了一个 Common Lisp 的 IDE - ...