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 ...
随机推荐
- cookie 和 session 的基础知识
cookie 和 session 的基础知识 cookie 和session 的区别详解 这些都是基础知识,不过有必要做深入了解.先简单介绍一下. 二者的定义: 当你在浏览网站的时候,WEB 服务器会 ...
- SQL——查询考试
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- uva10160 Servicing Stations
The input consists of more than one description of town (but totally, less than ten descriptions). E ...
- luogu2038[NOIP2014 T4]无线网络发射器选址
题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...
- jdbc连接数据库总结
jdbc支持多种数据库,比如说oracle, mysql, mssql,现在总结一下连接各种数据库的相关知识 1,mysql连接,代码如下 Class.forName("com.mysql. ...
- SPM paired t-test步骤
首先感谢大神空里流霜耐心的讲解,这篇笔记内容主要是整理他的谆谆教导,虽然他也看不到>< 所有数据都要经过平滑. Paired t-test虽然在2nd-level analysis中,但是 ...
- 4829 [DP]数字三角形升级版
4829 [DP]数字三角形升级版 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 从数字三角形的顶部(如图, ...
- 似魔鬼的 『 document.write 』
在平时的工作中,楼主很少用 document.write 方法,一直觉得 document.write 是个危险的方法.楼主不用,并不代表别人不用,最近给维护的项目添了一点代码,更加深了我对 &quo ...
- 你真的理解 new 了吗?
开篇先提几个问吧,如果你对这些问题都清楚了,那说明对于 new 这个关键字已经掌握得很好了,也不再需要花时间来阅读本文了, 1 new 一个class 与 new 一个Struct有什么 ...
- Linux下 RabbitMQ的安装与配置-3
一 Erlang安装 1.RabbitMQ是基于Erlang的,所以首先必须配置Erlang环境. 从Erlang的官网http://www.erlang.org/download.html 下载最 ...