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

这个题目很明显是唯一分解定理,但是如果你不知道唯一分解定理,那这个其实就有点难。

如果明白这个这个定理,那么这个题目就变得很容易了,这个题目就是运用了这个定理。

题目让你求一个数的分解形式有多少种,且分解成的最小的数要比给定数字大,

那不就是你求出有多少个正因数,然后除以2,这个求的就是对数。

然后减去不满足条件的。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e6;
int v[maxn],isp[maxn], m; void init1()
{
m = ;
memset(v, , sizeof(v));
for (int i = ; i < maxn; i++)
{
if (v[i] == )
{
isp[m++] = i;
v[i] = i;
}
for (int j = ; j < m; j++)
{
if (v[i]<isp[j] || i * isp[j]>maxn) break;
v[i*isp[j]] = isp[j];
}
}
} ll cont(ll x)
{
ll sum = ;
if (x == ) return ;
for(ll i=;i<m;i++)
{
ll num = ;
while(x%isp[i]==)
{
x /= isp[i];
num++;
}
sum *= num + ;
if (x == ) break;
}
if (x > ) sum *= ;
return sum;
} int main()
{
int t, cas = ;
init1();
cin >> t;
while(t--)
{
ll a, b;
cin >> a >> b;
if(b>=sqrt(a))
{
printf("Case %d: %d\n", ++cas, );
}
else
{
ll cnt = ;
for(ll i=;i<b;i++)
{
if (a%i == ) cnt++;
}
ll sum = cont(a) / ;
ll ans = sum - cnt;
printf("Case %d: %lld\n", ++cas, ans);
}
}
return ;
}

数论 C - Aladdin and the Flying Carpet的更多相关文章

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

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

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

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

  3. Aladdin and the Flying Carpet

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

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

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

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

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

  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(数论)

    题意 有一块矩形(也可能是正方形)的飞毯. 给定飞毯的面积\(n\)和最小可能的边长\(a\),求可能有多少种不同边长的飞毯.(\(1<=a<=n<=1e12\)) 如面积\(n=6 ...

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

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

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

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

随机推荐

  1. JDK对CAS ABA问题解决-AtomicMarkableReference和AtomicStampedReference

    我们知道AtomicInteger和AtomicLong的原子操作,但是在这两个类在CAS操作的时候会遇到ABA问题,可能大家会疑问什么是ABA问题呢,请待我细细道来: ABA问题:简单讲就是多线程环 ...

  2. javascript对象和数组之 深拷贝和浅拷贝

    管是在面试中还是我们的项目中经常会用到数组或者对象的深拷贝,下面我就自己总结的分享给大家. 首先要知道什么是深拷贝?什么是浅拷贝? 深拷贝:源对象与拷贝对象互相独立,其中任何一个对象的改动都不会对另外 ...

  3. React 与 React-Native 使用同一个 meteor 后台

    meteor 可以快速构建 pc,移动端,桌面端应用. 最大的优点是:数据库的数据发生变化时,可以实时推送到前端,非常适用于实时展示的应用开发. 在 react,react-native 应用中,可以 ...

  4. ubuntu-18.04 安装zsh的方法步骤

    zsh是一款跨平台的轻量级的终端,功能十分强大,会极大地提升你的工作效率.安装指南: ➜ ~ sudo apt-get install zsh ➜ ~ zsh --version #确认是否安装成功 ...

  5. JavaScript 执行机制

    一.宏任务与微任务 macro-task(宏任务):包括整体代码script,setTimeout,setInterval micro-task(微任务):Promise,process.nextTi ...

  6. Python基础(os模块)

    os模块用于操作系统级别的操作: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当 ...

  7. Vue.js-04:第四章 - 页面元素样式的设定

    一.前言 前端开发中有三大件:HTML.CSS.JavaScript,在前面的学习中,不管是学习 Vue 的指令系统还是 Vue 的事件修饰符,主要还是针对的是我们在前端开发中的 JavaScript ...

  8. List去重的实现

    List<T> 当T为值类型的时候 去重比较简单,当T为引用类型时,一般根据业务需要,根据T的中几个属性来确定是否重复,从而去重. 查看System.Linq下的Enumerable存在一 ...

  9. 你必须知道的.net读书笔记之第二回深入浅出关键字---对抽象编程:接口和抽象类

    请记住,面向对象思想的一个最重要的原则就是:面向接口编程. 借助接口和抽象类,23个设计模式中的很多思想被巧妙的实现了,我认为其精髓简单说来就是:面向抽象编程. 抽象类应主要用于关系密切的对象,而接口 ...

  10. 【开源分享】微信营销系统(第三方微信平台)github 开源

    升讯威微信营销系统(微信第三方平台) 在线体验:http://wxcm.eeipo.cn/开源地址GitHub:https://github.com/iccb1013/Sheng.WeixinCons ...