博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lightoj1341——Aladdin and the Flying Carpet(算术基本定理)
阅读量:2343 次
发布时间:2019-05-10

本文共 2041 字,大约阅读时间需要 6 分钟。

Description

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

题目给出a和b,a表示长方形的面积,b表示可能的最小的边,要求满足最小边不小于b的长方形的个数,且题目中提到不能为正方形。

算术基本定理:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积 N=P1a1P2a2P3a3……Pnan。——百度百科
那么就有以下推论
这里写图片描述
本题就是第一条推论的应用,求出a的正因子的个数,因为题目是要求满足最小边的个数,因此解最多是正因子个数的一半,再减去小于b即不满足题意的正因子的个数。另外还要特判b*b>=a的情况,不然会超时。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 1000005#define mod 1000000007using namespace std;long long p[MAXN],a[MAXN],cnt=0; //p保存素数,a判断当前数是否为素数void Primer(){ int i,j, k; for(i=2;i
=a) { printf("Case %d: 0\n",cnt++); continue; } ans=fac(a); ans/=2; for(long long i=1;i
你可能感兴趣的文章
在linux编程中,以下哪个TCP的套接字选项与nagle算法的开启和关闭有关?----腾讯2016研发工程师在线模拟笔试题
查看>>
某二叉树的先根遍历序列和后根遍历序列正好相反,则该二叉树具有的特征是()----腾讯2016研发工程师在线模拟笔试题
查看>>
win32系统里,下面几个sizeof的运行结果是()----腾讯2016研发工程师在线模拟笔试题
查看>>
若系统中有五台打印机,有多个进程均需要使用两台,规定每个进程一次仅允许申请一台,则在不发生死锁的情况下至多允许______个进程参与竞争
查看>>
关于红黑树和AVL树,以下哪种说法不正确?----腾讯2016研发工程师在线模拟笔试题
查看>>
关于epoll和select的区别,哪些说法是正确的?----腾讯2016研发工程师在线模拟笔试题
查看>>
以下是C++的不同数据类型值的比较语句,请问这些判断语句中作为条件部分的语句编写有问题的有:
查看>>
TCP链接中主动断开链接netstat观察可能出现的状态流转是:----腾讯2016研发工程师在线模拟笔试题
查看>>
以下涉及到内存管理的代码段中,有错误的是:----腾讯2016研发工程师在线模拟笔试题
查看>>
下面哪些特性可能导致代码体积膨胀:----腾讯2016研发工程师在线模拟笔试题
查看>>
const的使用方法----腾讯2016研发工程师笔试题(一)
查看>>
哪些设计模式是降低资源使用率:----腾讯2016研发工程师笔试题(一)
查看>>
n个顶点,m条边的全连通图,至少去掉____边才能构成一棵树?----腾讯2016研发工程师笔试题(一)
查看>>
在序列(22,34,55,77,89,93,99,102,120,140)中,采用二分查找,分别查找77,34,99,所需的查找次数分别为()----腾讯2016研发工程师笔试题(一)
查看>>
ip地址10.1.8.0/24和10.1.9.0/24,下列哪个是正确的汇总网段:----腾讯2016研发工程师笔试题(一)
查看>>
默认复制构造函数 bitwise 语义 delete 多次----腾讯2016研发工程师笔试题(一)
查看>>
在C++面向对象编程语言中,以下关于接口的阐述不正确的是:----腾讯2016研发工程师笔试题(一)
查看>>
下面关于HTTP协议的说法正确的是:----腾讯2016研发工程师笔试题(一)
查看>>
关于多线程和多进程编程,下面描述正确的是():----腾讯2016研发工程师笔试题(一)
查看>>
动态规划--钢条切割
查看>>