LightOJ 1341 唯一分解定理
Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
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 唯一分解定理的更多相关文章
- LightOJ - 1341唯一分解定理
唯一分解定理 先分解面积,然后除2,再减去面积%长度==0的情况,注意毯子不能是正方形 #include<map> #include<set> #include<cmat ...
- Aladdin and the Flying Carpet LightOJ 1341 唯一分解定理
题意:给出a,b,问有多少种长方形满足面积为a,最短边>=b? 首先简单讲一下唯一分解定理. 唯一分解定理:任何一个自然数N,都可以满足:,pi是质数. 且N的正因子个数为(1+a1)*(1+a ...
- LightOJ - 1236 (唯一分解定理)
题意:求有多少对数对(i,j)满足lcm(i,j) = n,1<=i<=j, 1<=n<=1e14. 分析:根据整数的唯一分解定理,n可以分解为(p1^e1)*(p2^e2)* ...
- lightoj 1220 唯一分解定理
#include<bits/stdc++.h> using namespace std; #define maxn 1000005 #define ll long long int v[m ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...
- LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria
题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
- lightoj 1236 正整数唯一分解定理
A - (例题)整数分解 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB 6 ...
随机推荐
- POJ1384Piggy-Bank[完全背包]
Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10787 Accepted: 5258 Descr ...
- Vijos1046观光旅游[floyd 最小环]
背景 湖南师大附中成为百年名校之后,每年要接待大批的游客前来参观.学校认为大力发展旅游业,可以带来一笔可观的收入. 描述 学校里面有N个景点.两个景点之间可能直接有道路相连,用Dist[I,J]表示它 ...
- AC日记——忽略大小写的字符串比较 openjudge 1.7 16
16:忽略大小写的字符串比较 总时间限制: 1000ms 内存限制: 65536kB 描述 一般我们用strcmp可比较两个字符串的大小,比较方法为对两个字符串从前往后逐个字符相比较(按ASCII ...
- Collider Collision 区别
Collision 中带有碰撞的信息,例如:速度和撞击到的点 示例 void OnCollisionEnter2D(Collision2D coll) { foreach(ContactPoint c ...
- StringBuffer和StringBuilder的区别
StringBuffer和StringBuilder的区别 StringBuffer与StringBuilder就不一样了,他们是字符串变量,是可改变的对象,每当我们用它们对字符串做操作时,实际上是在 ...
- 精通CSS version2笔记之⒈选择器
1.常用的选择器:①元素选择器 指定希望应用样式的元素.比如:p {color:#fff;}②后代选择器 寻找特定元素或者元素的后代. 比如:body p{color:#ccc;} 这个选 ...
- NSDate 哪些事
.什么是时间戳? 时间戳是自 1970 年 1 月 1 日(00:00:00 GMT)至当前时间的总秒数. 2.NSDate,时间戳,NSString 之间的转换 //string 转 date + ...
- JS中new都是干了些什么事情
var Person = function(name){ this.name = name; this.say = function(){ return "I am " + thi ...
- BZOJ 2440 【中山市选2011】 完全平方数
Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而这丝毫不影响他对其他数的热爱. 这天是 ...
- Javascript的ArrayBuffer从Utf8ArrayToString
由于项目需要,需要从一个已知的ArrayBuffer中读取出字符串,虽然环境是typescript,但最终还是用的js的代码改了一下解决, public Utf8ArrayToStr(array):s ...