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(唯一分解定理)的更多相关文章

  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. LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理

    题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet    PDF (English) S ...

  4. LightOJ 1341 Aladdin and the Flying Carpet 数学

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

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

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

  6. LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解

    http://www.lightoj.com/volume_showproblem.php?problem=1341 题意:给你长方形的面积a,边最小为b,问有几种情况. 思路:对a进行素因子分解,再 ...

  7. LightOJ 1341 - Aladdin and the Flying Carpet

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

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

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

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

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

随机推荐

  1. 进程Process之join、daemon(守护)、terminate(关闭)

    一.Process 参数介绍: 1 group参数未使用,值始终为None 2 target表示调用对象,即子进程要执行的任务 3 args表示调用对象的位置参数元组,args=(1,2,'a',) ...

  2. error: https://packages.elastic.co/GPG-KEY-elasticsearch: import read failed(2).

    安装filebeat报错: curl: (35) SSL connect errorerror: https://packages.elastic.co/GPG-KEY-elasticsearch: ...

  3. webpack无法通过 IP 地址访问 localhost 解决方案

    解决方案: 在config里面的index.js里面的module.exports下面的dev下面的host:'localhost' 改为 host:'0.0.0.0',就可以访问啦!

  4. jquery Chosen使用

    1,首先去http://harvesthq.github.io/chosen/下载插件. 2,在网页中加入下面的文件. <link rel="stylesheet" href ...

  5. NAND flash学习所获----(Zac)

    Nand Falsh外围电路:peripheral circuit 1.Nand flash里至少有2个state Machine(controller),即2个主控. 一个主控:负责处理前端事情. ...

  6. django后台数据管理admin设置代码

    新建admin用户 createsuperuser 设定好用户名,邮箱,密码 设置setting LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shangha ...

  7. spring boot 使用属性加载顺序

    1.命令行中传入的参数 2.SPRING_APPLICATION_JSON中的属性.SPRING_APPLICATION_JSON是以JSON格式配置再系统环境变量中的内容 3.java:comp/e ...

  8. mybatis-3 Dynamic SQL

    Dynamic SQL One of the most powerful features of MyBatis has always been its Dynamic SQL capabilitie ...

  9. 利用URLConnection来发送POST和GET请求

    URL的openConnection()方法将返回一个URLConnection对象,该对象表示应用程序和 URL 之间的通信链接.程序可以通过URLConnection实例向该URL发送请求.读取U ...

  10. 如何安装python .whl包

    1.最简单的办法是是python -mpip install *** 配置过环境变量也可以 pip install *** 但是由于墙的原因,很大概率失败.可以找到对应网站下载对应的.whl 2.下载 ...