LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1341
题意:
给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数。
思路:
根据唯一分解定理,把X写成若干素数相乘的形式,则X的正因数的个数为:(1+a1)(1+a2)(1+a3)...(1+an)。(ai为指数)
因为这道题目是求矩形,所以知道一个正因数后,另一个正因数也就确定了,所以每组正因数重复计算了两遍,需要除以2。
最后减去小于b的因数。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
using namespace std; const int maxn=1e6+; int n;
int cnt=;
int primes[maxn];
int vis[maxn]; void get_primes()
{
int m=sqrt(maxn+0.5);
for(int i=;i<=m;i++)
{
if(!vis[i])
{
for(int j=i*i;j<=maxn;j+=i)
vis[j]=;
}
}
for(int i=;i<=maxn;i++)
if(!vis[i]) primes[cnt++]=i;
} int main()
{
//freopen("D:\\input.txt","r",stdin);
int T;
int kase=;
get_primes();
scanf("%d",&T);
while(T--)
{
long long a,b;
scanf("%lld%lld",&a,&b);
long long x=a;
if(a<=b*b) {printf("Case %d: 0\n",++kase);continue;}
long long ans=;
for(int i=;i<cnt&&primes[i]*primes[i]<=a;i++)
{
if(a%primes[i]==)
{
long long num=;
while(a%primes[i]==)
{
num++;
a/=primes[i];
}
ans*=(+num);
}
}
if(a>) ans*=;
ans/=;
for(long long i=;i<b;i++)
if(x%i==) ans--;
printf("Case %d: %lld\n",++kase,ans);
}
return ;
}
LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)的更多相关文章
- 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 唯一分解定理LightOJ 1220Mysterious Bacteria
题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...
- LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理
题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet PDF (English) S ...
- LightOJ 1341 Aladdin and the Flying Carpet 数学
题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...
- [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))
题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...
- LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解
http://www.lightoj.com/volume_showproblem.php?problem=1341 题意:给你长方形的面积a,边最小为b,问有几种情况. 思路:对a进行素因子分解,再 ...
- LightOJ 1341 - Aladdin and the Flying Carpet
题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你地毯面积和最小可能边的长度,让你求有几种组合的可能. 题解:这题就厉害 ...
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1341 题意: 给定一个数,将其拆分成两个数的乘 ...
- LightOJ 1341 Aladdin and the Flying Carpet 算数基本定理
题目大意:给出面积n,和最短边m,求能形成的矩形的个数(不能为正方形). 题目思路:根据算数基本定理有: 1.每个数n都能被分解为:n=p1^a1*p2^a2*^p3^a3……pn^an(p为素数); ...
随机推荐
- python爬虫系列(2)—— requests和BeautifulSoup
本文主要介绍python爬虫的两大利器:requests和BeautifulSoup库的基本用法. 1. 安装requests和BeautifulSoup库 可以通过3种方式安装: easy_inst ...
- python argparse命令行参数
测试: 第一个没有任何输出和出错 第二个测试为打印帮助信息,argparse会自动生成帮助文档 第三个测试为未定义的-v参数,会出错 第四个测试为未定义的参数foo,出错 positional arg ...
- 2.AS入门教程
AndroidStudio 本文是关于androidStudio的一些基础知识 介绍 Google官方的Android集成开发环境(IDE = Integrated Development Envir ...
- gui设计
芯艺,你好! ... ... ... 芯艺,再见! http://www.chipart.cn/ 附件 http://files.cnblogs.com/files/dong1/%E8%89%BA%E ...
- Intellij IDEA如何使用Maven Tomcat Plugin运行web项目
首先,Run ——> Edit Configurations,这时候如下图: 然后点击左上角的加号,可以添加一个新的配置,如下图: 选择Maven,如下图: 下面填上自己的配置信息,点击appl ...
- PAT 1033 To Fill or Not to Fill[dp]
1033 To Fill or Not to Fill(25 分) With highways available, driving a car from Hangzhou to any other ...
- SQL Server outer apply 和 cross apply
先说点题外话,因为后面我会用到这个函数. 前两天自定义了一个 sql 的字符串分割函数(Split),不过后来发现有点问题,例如: select * from Split(default,'123,4 ...
- 清晰讲解LSB、MSB和大小端模式及网络字节序
时隔一个月又回到了博客园写文章,很开心O(∩_∩)O~~ 今天在做需求的涉及到一个固件版本的概念,其中固件组的人谈到了版本号从MSB到LSB排列,检索查阅后将所得整理如下. MSB.LSB? MSB( ...
- 【转】Google的2012论文
转自:http://www.sigvc.org/bbs/thread-1152-1-1.html Google的论文一直是业界的风向标,尤其在机器学习.分布式系统.网络等方面很多创新性的成果都是由他们 ...
- $Linux vi/vim编辑器常用命令与用法总结 (Markdown编辑版)
vi/vim是什么? Linux世界几乎所有的配置文件都是以纯文本形式存在的,而在所有的Linux发行版系统上都有vi编辑器,因此利用简单的文字编辑软件就能够轻松地修改系统的各种配置了,非常方便.vi ...