Aladdin and the Flying Carpet

Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Appoint description: 
System Crawler  (2016-07-08)

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: ab(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

1.有多少个约数:

先分解质因数
因数的次数分别是4,2,1

所以约数的个数为(4+1)*(2+1)*(1+1)=5*3*2=30个

eg:

先分解质因数

720=24*32*51

因数的次数分别是4,2,1

所以约数的个数为(4+1)*(2+1)*(1+1)=5*3*2=30个

2.所有约数之和:

2004的约数之和为:1, 2, 3, 4, 6, 12, 167, 334, 501, 668, 1002 ,2004  = 4704

如何求一个数所有约数之和呢?

首先,应用算术基本定理,化简为素数方幂的乘积。

X = a1^k1 * a2^k2........an^kn

X的所有素数之和可用公式(1+a1 + a1^2...a1^k1) * (1+a2 + a2^2...a2^k2) * .....(1+an + an^2...an^kn)表示

如:

2004 = 2^2  * 3  *167

2004所有因子之和为(1  + 2 + 2^2) * (1 + 3) * ( 1 + 167) = 4704;

程序实现的时候,可利用等比数列快速求1 + a1 + a1^2 + .....a1^n;

思路:

求出它的每个质因子的个数,然后用公式求出它的约数个数。如果b * b > a,那么值一定为0,其余部分可以枚举b,删除。但是我觉得枚举应该会挂掉,

但是竟然没有挂。。

/*
* Author: sweat122
* Created Time: 2016/7/11 14:53:29
* File Name: main.cpp
*/
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<time.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define key_value ch[ch[root][1]][0]
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
int notprime[MAXN],prime[MAXN],cnt;
ll a,b;
void init(){
cnt = ;
memset(prime,,sizeof(prime));
memset(notprime,,sizeof(notprime));
for(int i = ; i < MAXN - ; i++){
if(!notprime[i]){
prime[cnt++] = i;
}
for(int j = ; j < cnt && 1LL * prime[j] * i < MAXN - ; j++){
notprime[prime[j] * i] = ;
if(i % prime[j] == ) break;
}
}
}
int main(){
int t,Case = ;
init();
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&a,&b);
ll ans = ;
ll x = a;
for(int i = ; i < cnt; i++){
if(prime[i] > x)break;
if(x % prime[i] == ){
int num = ;
while(x % prime[i] == ){
num += ;
x /= prime[i];
}
ans *= (num + );
}
}
if(x > ) ans *= ( + );
ans /= ;
if(b * b > a){
printf("Case %d: %lld\n",++Case,);
} else{
for(int i = ; i < b; i++){
if(a % i == ) ans -= ;
}
printf("Case %d: %lld\n",++Case,ans);
}
}
return ;
}

LightOJ 1341 唯一分解定理的更多相关文章

  1. LightOJ - 1341唯一分解定理

    唯一分解定理 先分解面积,然后除2,再减去面积%长度==0的情况,注意毯子不能是正方形 #include<map> #include<set> #include<cmat ...

  2. Aladdin and the Flying Carpet LightOJ 1341 唯一分解定理

    题意:给出a,b,问有多少种长方形满足面积为a,最短边>=b? 首先简单讲一下唯一分解定理. 唯一分解定理:任何一个自然数N,都可以满足:,pi是质数. 且N的正因子个数为(1+a1)*(1+a ...

  3. LightOJ - 1236 (唯一分解定理)

    题意:求有多少对数对(i,j)满足lcm(i,j) = n,1<=i<=j, 1<=n<=1e14. 分析:根据整数的唯一分解定理,n可以分解为(p1^e1)*(p2^e2)* ...

  4. lightoj 1220 唯一分解定理

    #include<bits/stdc++.h> using namespace std; #define maxn 1000005 #define ll long long int v[m ...

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

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

  6. LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)

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

  7. LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria

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

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

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

  9. lightoj 1236 正整数唯一分解定理

    A - (例题)整数分解 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     6 ...

随机推荐

  1. JavaSE之概述与基本语法

    嘛,这个本来应该发在OOP之前的,无所谓了,补发一下,这篇文章只会对JavaSE的语法做一个基本的概述而已,我会在最近新开一个新坑,也就是JavaEE系列,以后还会有Cpp(相对于C++,我还是更喜欢 ...

  2. VS的快捷键F12改成和ECLIPSE一样用ctrl+点击下载线

    安装resharper 插件即可 不过这个插件是收费的,可免费体验30天

  3. 入门训练 Fibonacci数列

      入门训练 Fibonacci数列   时间限制:1.0s   内存限制:256.0MB 问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n比较大时, ...

  4. window.execScript的兼容性写法

    把探嗅浏览器的操作提前到代码加载的时候,在代码加载的时候就立刻进行一次判断,以便让globalEval返回一个包裹了正确逻辑的函数 var globalEval = (function(){ var ...

  5. Maven 常用命令, 备忘

    Maven在现在的Java项目中有非常重要的地位, Maven已经不是Ant这样仅仅用于构建, 首先, 它是一个构建工具, 把源代码编译并打包成可发布应用的构件工具其次, 它是一个依赖管理工具, 集中 ...

  6. X200s,Debian 8(Jessie) 安装流水帐

    1. U盘启动安装 a. 因为无线网卡驱动是non-free,需要另外下载,对应X200s,文件是iwlwifi-5000-5.ucode,下完放到安装U盘的根目录下,安装时就不会再提示而是直接安装  ...

  7. JS给文本框赋值后,在页面后台取不到文本框值的解决方法

    转自:http://www.cnblogs.com/qiaohd/archive/2012/03/23/2413660.html (ReadOnly.disabled 都有可能造成取值取不到) 开发一 ...

  8. 玩转Android Camera开发(二):使用TextureView和SurfaceTexture预览Camera 基础拍照demo

    Google自Android4.0出了TextureView,为什么推出呢?就是为了弥补Surfaceview的不足,另外一方面也是为了平衡GlSurfaceView,当然这是本人揣度的.关于Text ...

  9. 进程控制块(Process Control Block, PCB)

    是为了管理进程设置的一个数据结构.是系统感知进程存在的唯一标志.通常包含如以下的信息:(1)进程标识符(唯一)(2)进程当前状态,通常同一状态的进程会被放到同一个队列:(3)进程的程序和数据地址(4) ...

  10. 发布园友设计的新款博客皮肤BlueSky

    园友#a为大家设计了一款“简单.纯粹,一点淡雅,一点宁静”的博客皮肤——BlueSky,欢迎您的享用!感谢#a的精心设计! 如果您有兴趣为大家设计博客皮肤,请将您设计的html/css/images文 ...