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 ...
随机推荐
- KSFramework配置表:扩展表格解析类型
解析和扩展表格 配置表示例 配置表模块在编译时,把Excel转化成TSV,并根据Excel的头部信息,生成对应的代码: 比如源码库中的Test.xlsx Excel文件,两个列头,Id和Value,其 ...
- cache缓存
缓存分为:数据缓存,页面缓存,内存缓存(memcache,redis) ob,输出缓冲区,是output buffering的简称 FileCache.php <?php //本文件用来存储和读 ...
- http协议(四)http状态码
一:http状态码 表示客户端http请求的返回结果.标记服务器端的处理是否正常.通知出现的错误等工作 状态码的类别如下: http状态码种类繁多,大概有60多种,实际上经常使用的只有14种,下面为一 ...
- IO调度器(二) IO的中断返回
IO的中断返回也是相当让人激动的一件事情: 28470 1) | handle_irq() { 28471 1) 0.237 us | ...
- blogs for learning java
曹海成的专栏 http://blog.csdn.net/caohaicheng/article/details/38071097 http://blog.csdn.net/a5489888/artic ...
- 协程python
python中协程 在引出协成概念之前先说说python的进程和线程. 进程: 进程是正在执行程序实例.执行程序的过程中,内核会讲程序代码载入虚拟内存,为程序变量分配空间,建立 bookkeeping ...
- Java调用C/C++编写的第三方dll动态链接库(zz)
这里主要用的方法是JNI.在网上查资料时看到很多人说用JNI非常的复杂,不仅要看很多的文档,而且要非常熟悉C/C++编程.恐怕有很多人在看到诸如此类的评论时已经决定绕道用其他方法了.本文将做详细的介绍 ...
- mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理
1.mvc5+ef6+Bootstrap 项目心得--创立之初 2.mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理 3.mvc5+ef6+Bootstrap 项目心得--WebG ...
- .net破解二(修改dll)
多谢大家支持! 昨天说了一下反编译与剥壳(.net破解一(反编译,反混淆-剥壳,工具推荐)),今天就来修改修改dll,为了方便,我自己写一个简单程序用来测试 代码如下: 一个 ConsoleAppli ...
- Euler Level 2
闲下来的时候就做点,慢慢的也终于到达Level 2了.