题目链接:https://vjudge.net/problem/LightOJ-1341

1341 - Aladdin and the Flying Carpet
Time Limit: 3 second(s) Memory Limit: 32 MB

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

Output for Sample Input

2

10 2

12 2

Case 1: 1

Case 2: 2

题意:

求n有多少对因子(即a*b=n,则{a,b}为其中一对,不要求顺序),且因子的最小下限为m?

题解:

1.求因子个数,则对n进行质因子分解。

2.先不考虑因子的最小下限m,则n共有 ∏(num[i]+1)个因子,其中num[i]为第i个质因子的个数。

3.当n是平方数的时候,除了sqrt(n)之外,其他因子是一一对应的,即a*b=n, a!=b; 当n不是平方数时,显然它的因子是一一对应的,即有2*pair个因子,所以有pair对因子, 因此 pair = (∏(num[i]+1))/2,而题目说明了n非平方数。

4.再考虑回下限m:可知当 a*b = n 时, a、b必定满足 a<=sqrt(n)或b<=sqrt(n)。所以当m>sqrt(n)时,就不存在这样的因子对。当m<=sqrt(n)时,可以直接枚举较小的那个因子,枚举范围为:1~min(m, sqrt(n)+1),如果它能整除n,这表明存在一对不满足最小下限的因子对,删除即可。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e6+; LL n, m;
bool notprime[MAXN];
int prime[MAXN+];
void getPrime()
{
memset(notprime, false, sizeof(notprime));
notprime[] = notprime[] = true;
prime[] = ;
for (int i = ; i<=MAXN; i++)
{
if (!notprime[i])prime[++prime[]] = i;
for (int j = ; j<=prime[ ]&& prime[j]<=MAXN/i; j++)
{
notprime[prime[j]*i] = true;
if (i%prime[j] == ) break;
}
}
} int fatCnt;
LL factor[][];
int getFactors()
{
LL tmp = n;
fatCnt = ;
for(int i = ; prime[i]<=tmp/prime[i]; i++)
{
if(tmp%prime[i]==)
{
factor[++fatCnt][] = prime[i];
factor[fatCnt][] = ;
while(tmp%prime[i]==) tmp /= prime[i], factor[fatCnt][]++;
}
}
if(tmp>) factor[++fatCnt][] = tmp, factor[fatCnt][] = ;
} int main()
{
getPrime();
int T, kase = ;
scanf("%d", &T);
while(T--)
{
scanf("%lld%lld", &n,&m);
int ans = ;
if(1LL*m*m>n)
ans = ;
else
{
getFactors();
for(int i = ; i<=fatCnt; i++)
ans *= (factor[i][]+);
ans /= ;
for(LL i = ; i<min(m,(LL)sqrt(n)+); i++)
if(n%i==) ans--;
}
printf("Case %d: %lld\n", ++kase, ans);
}
}

LightOJ1341 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. LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria

    题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...

  3. LightOJ-1341 Aladdin and the Flying Carpet 分解质因数(注意对大素数的优化)

    题目链接:https://cn.vjudge.net/problem/LightOJ-1341 题意 给出一个长方形的面积a 让你算整数边长的可能取值,并且两个边都大于给定数字b 思路 唯一分解定理: ...

  4. LightOJ1341 Aladdin and the Flying Carpet

    题意 给一对数字 a,b ,a是一个长方形的面积,问有多少种整数的边的组合可以组成面积为a的长方形,要求最短的边不得小于b 数据组数T<=4000, a,b<=10^12 Solution ...

  5. Aladdin and the Flying Carpet

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

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

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

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

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

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

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

  9. Aladdin and the Flying Carpet(唯一分解定理)

    题目大意:给两个数a,b,求满足c*d==a且c>=b且d>=b的c,d二元组对数,(c,d)和(d,c)属于同一种情况: 题目分析:根据唯一分解定理,先将a唯一分解,则a的所有正约数的个 ...

随机推荐

  1. 最简单的window下使用Jenkins来做自动化部署的教程

    今天我们来说一下,如何使用Jenkins+powershell脚本,将我们的.NET CORE的脚本部署到对应的服务器上. 这里我们使用的源码管理工具是TFS.虽然源码管理器比较老旧,但是原理都差不多 ...

  2. vs code theme Seti monokai

    http://www.jianshu.com/p/80e983201f86 Seti-UI主题是一款极具传奇色彩的主题

  3. JavaScript : 零基础打造自己的jquery类库

    写作不易,转载请注明出处,谢谢. 文章类别:Javascript基础(面向初学者) 前言 在之前的章节中,我们已经不依赖jQuery,单纯地用JavaScript封装了很多方法,这个时候,你一定会想, ...

  4. Android设置TextView行间距(非行高)

    Android设置TextView行间距(非行高) Android系统中TextView默认显示中文时会比较紧凑,不是很美观. 为了让每行保持一定的行间距,可以设置属性android:lineSpac ...

  5. win7 32位安装pyqt

    参考 http://blog.csdn.net/fairyeye/article/details/6607981 http://www.cnblogs.com/toSeek/p/6363036.htm ...

  6. 调用tf.softmax_cross_entropy_with_logits函数出错解决

    原来这个函数,不能按以前的方式进行调用了,只能使用命名参数的方式来调用.原来是这样的: tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y ...

  7. python(36)- 测试题

    1.8<<2等于? 32 “<<”位运算 264 132 64 32 16 8 4 2 1 原始位置 0 0 0 0 0 1 0 0 0 想左位移2位 0 0 0 1 0 0 ...

  8. ffmpeg rtmp 推流错误WriteN, RTMP send error 10053 10038

    利用ffmepg推264流到rtmp服务端出现错误WriteN, RTMP send error 10053,具体如下图所示. 图1推流到rtmp服务错误 原因是视频流缺少SPS,PPS信息,加上这两 ...

  9. mysql 中遇到金额 BigDecimal类型字段

    当数据库字段为BigDecimal型,and后面判断去掉. 否则当为0时候,视为空处理了.即传参为null

  10. Webview页面的控件元素定位

    前言 现在有很多App都是Hybrid的,即有原生的页面又有Webview的页面,元素的可以通过uiautomatorviewer工具 进行控件元素的定位,Webview页面的则无法通过此方式定位,而 ...