题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形)

分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a)

所以找到所有小于sqrt(a)的因子,看有几个大于等于b的就是方案数

因子可以由数的唯一分解定理,求得

具体 : 先筛一遍1e6以内的素数,有线性筛,然后分解a,然后dfs找所有的小于sqrt(a)的因子,

由于前12个素数的乘积大于1e12了,所以这部分复杂度,大概是O(2^12)(一般还要略大,不过大不了多少,数组要开大)左右

可以用这个估计(因为是求小于sqrt(a)的,可以除以2,当然这是空间常数)

所以这部分复杂度是O(T*2^12)满的话(4000*4000)大概也就是几百万,这部分可以忽略不计

主要的复杂度在分解素数里,因为1e6里面大概有7w多素数,这部分复杂度(最坏的情况a是大素数),大概是4000*70000,可以卡过,由于不可能都是这种数据

所以还是可以过的

吐槽:然后我看了看网上的代码,都是先求出总的,然后暴力扫b减,结果居然过了,b是sqrt(a)的级别,是百万,4000*1e6,是4e9,TLE

出题人太良心,没有卡这种的QAQ,感觉略坑啊

#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e6+;
const int INF=0x3f3f3f3f;
int cnt;
bool v[N];
LL prime[];
void getprime(){
for(int i=;i*i<=N-;++i)
if(!v[i])
for(int j=i*i;j<=N-;j+=i)
v[j]=;
for(int i=;i<=N-;++i)
if(!v[i])prime[++cnt]=i;
}
vector<LL>fac[];
int divisors[],tot;
LL k;
void dfs(int pos,LL res){
if(pos==fac[].size()){
divisors[++tot]=res;
return;
}
for(LL i=,now=;i<=fac[][pos];now*=fac[][pos],++i){
if(now*res>=k)break;
dfs(pos+,res*now);
}
}
int main()
{
getprime();
int cas=,T;
scanf("%d",&T);
while(T--){
printf("Case %d: ",++cas);
LL a,b;
scanf("%lld%lld",&a,&b);
k=sqrt(a);
if(k*k!=a)++k;
if(b>=k){
printf("0\n");
continue;
}
LL t=a;
fac[].clear(),fac[].clear();
for(int i=;i<=cnt&&prime[i]*prime[i]<=t;++i){
if(t%prime[i])continue;
int tmp=;
fac[].push_back(prime[i]);
while(t%prime[i]==)++tmp,t/=prime[i];
fac[].push_back(tmp);
}
if(t>){
fac[].push_back(t);
fac[].push_back();
}
tot=;
dfs(,);
int ans=;
for(int i=;i<=tot;++i)
if(divisors[i]>=b)++ans;
printf("%d\n",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. LightOJ 1341 - Aladdin and the Flying Carpet

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

  4. LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)

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

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

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

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

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

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

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

  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. js中的in-for循环

    <!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...

  2. 实时监听input输入框value值的变化

    1.js 的 oninput & onpropertychange JS中的 oninput 事件在 IE9 以下版本不支持,需要使用 IE 特有的 onpropertychange 事件替代 ...

  3. C# 实体model验证输出

    新建Model实体: [Required(ErrorMessage = @"地址 1 为必填项!")] [StringLength(, ErrorMessage = @" ...

  4. 升级iOS10后SearchController焦点无法获取的问题

    原来在没升级之前,是这样获取的,好使 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.sea ...

  5. yii2配置表前缀

    前缀设置 component中db的配置修改 'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=xxxx', ...

  6. How to open .ccproj in VS2010?

    Q: How to open .ccproj projects types in VS2010, ccproj file type is a Cloud project i suppose. Plea ...

  7. cin、cin.get()、cin.getline()、getline()、gets()等函数的用法

    学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有所帮助,如果有差错的地方还请各位多多指教(本文所有程序均通过VC 6.0运行)转载请保留作者信息:1.cin1 ...

  8. VM启动报错:Failed to lock the file

    http://www.cnblogs.com/kristain/articles/2491966.html Reason: Failed to lock the fileGoogle 了一下, 在網路 ...

  9. c++中的static关键字

    1.在函数体中,一个被声明为静态的变量在这一函数被调用的过程中维持其值不变. 2.在模块内(但在函数外),比如在某一个C源文件内,一个被声明为静态的变量可以被该模块内的所有函数调用,但不能被模块外的函 ...

  10. css清除浮动的几种方法整理

    四种清除浮动方法如下: 1.使用空标签清除浮动.空标签可以是div标签,也可以是P 标签.这种方式是在需要清除浮动的父级元素内部的所有浮动元素后添加这样一个标签 清除浮动,并为其定义CSS代码:cle ...