http://www.lightoj.com/volume_showproblem.php?problem=1341

题意:给你长方形的面积a,边最小为b,问有几种情况。

思路:对a进行素因子分解,再乘法原理算一下,最后减去小于b的因子的情况即可。

/** @Date    : 2016-12-01-19.04
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/ #include<bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e6+20; LL pri[N];
int c = 0;
bool vis[N]; void prime()
{
for(int i = 2; i <= N; i++)
{
if(!vis[i])
{
for(int j = i + i; j <= N; j+= i)
{
if(!vis[j])
vis[j] = 1;
}
pri[c++] = i;
}
}
}
int main()
{
prime();
int T;
int cnt = 0;
cin >> T; while(T--)
{
LL a , b;
scanf("%lld%lld", &a, &b); LL t = a;
LL ans = 1;
LL cc = 0;
if(b > sqrt(a))
{
printf("Case %d: 0\n", ++cnt);
continue;
}
for(int i = 0; i < c && pri[i]*pri[i] <= t; i++)
{
LL cc = 0;
while(t % pri[i] == 0)
{
cc++;
t /= pri[i];
}
ans *= cc + 1;
}
if(t > 1)
ans *= 2; ans /= 2;
for(int i = 1; i < b; i++)
if(a % i == 0)
{
ans--;
} printf("Case %d: %lld\n", ++cnt, ans);
}
return 0;
}

LightOJ 1341 - 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(唯一分解定理)

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

  4. LightOJ 1341 - Aladdin and the Flying Carpet

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你地毯面积和最小可能边的长度,让你求有几种组合的可能. 题解:这题就厉害 ...

  5. LightOJ 1341 Aladdin and the Flying Carpet【整数分解】

    题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1341 题意: 给定一个数,将其拆分成两个数的乘 ...

  6. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

  7. LightOJ 1341 Aladdin and the Flying Carpet 数学

    题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...

  8. LightOJ 1341 Aladdin and the Flying Carpet 算数基本定理

    题目大意:给出面积n,和最短边m,求能形成的矩形的个数(不能为正方形). 题目思路:根据算数基本定理有: 1.每个数n都能被分解为:n=p1^a1*p2^a2*^p3^a3……pn^an(p为素数); ...

  9. LightOJ 1341 Aladdin and the Flying Carpet(整数拆分定理)

    分析:题目并不难理解,就是一些细节上的优化需要我们注意,我在没有优化前跑了2000多MS,优化了一些细节后就是400多MS了,之前还TLE了好几次. 方法:将整数拆分为质因子以后,表达为这样的形式,e ...

随机推荐

  1. GitHub把自己整个文件夹上传

    我已经有了自己github,但是我怎么对我的项目进行上传呢,普通的上传只有上传单一的文件 这不我去下载了Git(链接至机房ftp文件夹下文件ftp://10.64.130.1/%C8%ED%BC%FE ...

  2. iconFont 阿里巴巴矢量图标使用方法

    挑选图标的过程(共6步) 进入网站:Iconfont网址:http://www.iconfont.cn 点击网站上方的“官方图标库”,选择自己喜欢的图标.在这里我选择天猫的图标库. 选择好自己喜欢的图 ...

  3. html+css基础 - 个人备忘录

    //======================html部分===================// 表现内容<meta http-equiv="Content-Type" ...

  4. 20172332 实验一《Java开发环境的熟悉》实验报告

    20172332 2017-2018-2 <程序设计与数据结构>实验一报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 于欣月 学号:20172332 实验教师:王 ...

  5. Spark GraphX 2

    顶点:VertexRDD   边:EdgeRDD.Edge.EdgeDirection   Triplet:EdgeTriplet   存储:PartitionStrategy 通常的存储方式有两种: ...

  6. Swift-map()跟flatMap()区别

    map()方法介绍 map() 是  Array 提供的方法,通过接收一个函数作为传入参数,对数组中每个元素进行函数变换得到新的结果值.这样只需要提供  X->Y 的映射关系,就能将数组  [X ...

  7. C#之WCF入门1—简单的wcf例子

    第一步:创建一个空的解决方案,新建一个WCF服务应用程序项目(使用默认名字) 来模拟服务端,新建一个控制台应用程序项目(名称改为 ConsoleApp)来模拟客户端. 第二步:简单分析WcfServi ...

  8. PokeCats开发者日志(十三)

      现在是PokeCats游戏开发的第六十二天的晚上,把软著权登记证书的截图加上,又重新提交审核了一遍,但愿能过吧...

  9. xpath教程二 ---- 通过ID和Class检索

    必备知识点 在html中,id是唯一的 在html中,class是可以多处引用的 工具 Python3版本 lxml库[优点是解析快] HTML代码块[从网络中获取或者自己杜撰一个] requests ...

  10. 【Linux】- CentOS 防火墙iptables和firewall

    1 iptables防火墙 1.1 基本操作 # 查看防火墙状态 service iptables status   # 停止防火墙 service iptables stop   # 启动防火墙 s ...