题意:求大于b的a的因数对有几组。例10  2结果为{2,5},12 2结果为{2,6}{3,4}-----不反复

解一:分解质因数+DFS

#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
typedef long long ll;
const int maxn=1000005;
int prime[maxn];
int num[maxn];
int dig[200];
int dignum[200];
int p;
void inti() //筛选素数
{
p=0;
memset(prime,0,sizeof(prime));
memset(num,0,sizeof(num));
for(int i=2;i<maxn;i++)
{
if(!prime[i])
{
num[p++]=i;
for(int j=2;j*i<maxn;j++)
prime[i*j]=1;
}
}
return ;
}
ll pp;
void dfs(ll tot,int t,int l,ll a,ll b) //dfs找到全部符合的因数
{
if(((double)tot*tot)>=a)
return ;
if(tot>=b)
pp++;
for(int i=t;i<l;i++)
{
if(dig[i])
{
ll temp=tot*dignum[i];
if(((double)temp*temp)>=a)
return ;
dig[i]--;
dfs(temp,i,l,a,b);
dig[i]++;
}
}
return ;
}
int main()
{
ll a,b;
int t;
inti();
while(cin>>t)
{
for(int i=1;i<=t;i++)
{
pp=0;
cin>>a>>b;
double limit=sqrt(a*1.0);
if(b>=limit)
{
cout<<"Case "<<i<<": 0"<<endl;
continue;
}
ll temp=a;
int j=0;
int time=0;
while(j<=p) //全部的质因数
{
if((ll)num[j]*num[j]>temp) //小小的剪枝
break;
int flag=0;
while(!(temp%num[j]))
{
temp/=num[j];
flag++;
}
if(flag)
{
dignum[time]=num[j];
dig[time++]=flag;
}
j++;
}
if(temp!=1)
{
dignum[time]=temp;
dig[time++]=1;
}
/*for(j=0;j<time;j++)
cout<<dignum[j]<<" "<<dig[j]<<endl;*/
dfs(1,0,time,a,b);
cout<<"Case "<<i<<": "<<pp<<endl;
}
}
return 0;
}

解二:直接计算

#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
typedef long long ll;
const int maxn=1000005;
int prime[maxn];
int num[maxn];
int dig[200];
int dignum[200];
int p;
void inti() //找素数
{
p=0;
memset(prime,0,sizeof(prime));
memset(num,0,sizeof(num));
for(int i=2;i<maxn;i++)
{
if(!prime[i])
{
num[p++]=i;
for(int j=2;j*i<maxn;j++)
prime[i*j]=1;
}
}
return ;
}
/*ll pp;
void dfs(ll tot,int t,int l,ll a,ll b)
{
if(((double)tot*tot)>=a)
return ;
if(tot>=b)
pp++;
for(int i=t;i<l;i++)
{
if(dig[i])
{
ll temp=tot*dignum[i];
if(((double)temp*temp)>=a)
return ;
dig[i]--;
dfs(temp,i,l,a,b);
dig[i]++;
}
}
return ;
}*/
int main()
{
ll a,b;
int t;
inti();
ll sum;
while(cin>>t)
{
for(int i=1;i<=t;i++)
{
sum=1;
cin>>a>>b;
if(((double)b*b)>=a)
{
cout<<"Case "<<i<<": 0"<<endl;
continue;
}
ll temp=a;
int j=0;
int time=0;
while(j<=p)
{
if((double)num[j]*num[j]>temp)
break;
int flag=0;
while(!(temp%num[j]))
{
temp/=num[j];
flag++;
}
sum*=(flag+1); //排列组合。把全部的情况拿出来
j++;
}
if(temp!=1)
{
sum*=2; //还有没除尽的要给全部可能性乘2
}
sum/=2; //直接除2,把反复的部分和正方形除去了
ll limit=sqrt(a*1.0);
for(j=1;j<b;j++) //去掉不符合要求的矩形
if(!(a%j))
sum--;
/*for(j=0;j<time;j++)
cout<<dignum[j]<<" "<<dig[j]<<endl;*/
//dfs(1,0,time,a,b);
cout<<"Case "<<i<<": "<<sum<<endl;
}
}
return 0;
}

第一种方法easy爆站。另外一种方法算是凑着它数据的b偏小才这么做的,两种方法个人感觉差点儿相同,希望各位大牛指正。

Light OJ 1341 Aladdin and the Flying Carpet的更多相关文章

  1. Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS

    进入a b 多少努力p, q 使p*q == a && p < q && p >= b 直接大整数分解 然后dfs所有可能的解决方案劫持 #include ...

  2. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  3. 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)

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

  4. LOJ 1341 Aladdin and the Flying Carpet(质因子分解)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给两个数a,b,求满足c * d = a且c>=b且d>=b的 ...

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

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

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

  8. LightOJ 1341 - Aladdin and the Flying Carpet

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

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

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

随机推荐

  1. Calling Mojo from Blink

    Variants Let's assume we have a mojom file such as this:   module example.mojom;   interface Foo {   ...

  2. div控制最小高度又自适高度

    div控制最小高度又自适高度我们在用div布局的时候经常会遇到这样的一种情况:我们需要设置一个div的高度,当里面的东西超过这个高度时,让这个容器自动被撑开,也就是自适应高度.当里面的信息很少时候,我 ...

  3. 4----COM:a Generative Model for group recommendation(组推荐的一种生成模型)

    1.摘要: 组推荐的一个挑战性问题:因为不同组的成员就有不同的偏好,如何平衡这些组员的偏好是一个难以解决的问题. 在本文中,作者提出了一个COM的概率模型来建立组活动生成过程. 直觉上: 一个组中的用 ...

  4. Linux 和 Windows 双系统时间同步问题 修改注册表

    路径:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation 1:新建  >> DWORD(32 b ...

  5. Python学习————集合的增删查

    可变的数据类型,他里面的元素必须是不可变的数据类型.无序,内容不能重复.应用于去重 增加:set1.add('元素')--->将元素无序的插入集合set1中set1.update("元 ...

  6. 紫书 习题 11-2 UVa 1001 (Floyd)

    这道题只是在边上做一些文章. 这道题起点终点可以看成半径为0的洞, 我是直接加入了洞的数组. 边就是两点间的距离减去半径, 如果结果小于0的话, 距离就为0, 距离不能为负 然后我看到n只有100, ...

  7. Docker学习总结(8)——利用Docker开启持续交付之路

    持续交付即Continuous Delivery,简称CD,随着DevOps的流行正越来越被传统企业所重视.持续交付讲求以短周期.小细粒度,自动化的方式频繁的交付软件,在这个过 程中要求开发.测试.用 ...

  8. Java基础学习总结(6)——面向对象

    一.JAVA类的定义 JAVA里面有class关键字定义一个类,后面加上自定义的类名即可.如这里定义的person类,使用class person定义了一个person类,然后在person这个类的类 ...

  9. 洛谷——P1428 小鱼比可爱

    https://www.luogu.org/problem/show?pid=1428 题目描述 人比人,气死人:鱼比鱼,难死鱼.小鱼最近参加了一个“比可爱”比赛,比的是每只鱼的可爱程度.参赛的鱼被从 ...

  10. Memcached windows安装

    Memcached windows安装 如果出现提示: Microsoft Windows [版本 6.3.9600] (c) 2013 Microsoft Corporation.保留所有权利. D ...