题意:求大于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. (WC2016模拟十八)【BZOJ4299】[CodeChef]FRBSUM

    咕了若干天我终于来补坑了qwq HINT $1\leq N,M\leq 10^5$ $1\leq \sum A_i\leq 10^9$ 题解: 虽然场上做出来了但还是觉得好神啊! 假设当前集合能凑出$ ...

  2. 【xsy2440】【GDOI2016】疯狂动物城

    感受一下这恐怖的题目长度~~~ 其实题意很裸,但是作为GDOI的一道防AK题,自然有他优秀的地方. 简化题意:给出一棵树,要求支持三个操作: 1.修改点值 2.询问点$x$到$y$之间的一些东东 3. ...

  3. tinymce原装插件源码分析(六)-preview

    priview 此插件文件结构比较简单,按钮注册.editor.windowManager.open.窗口出现之前的渲染数据的准备.页面代码的准备. 注意: 1.preview的默认宽高设置: 2.c ...

  4. JS函数传参传入对象

    例如: value为一个对象 value={} var valueStr = JSON.stringify(value); 对象转字符串 "<a style='cursor: poin ...

  5. 紫书 习题 8-25 UVa 11175 (结论证明)(配图)

    看了这篇博客https://blog.csdn.net/u013520118/article/details/48032599 但是这篇里面没有写结论的证明, 我来证明一下. 首先结论是对于E图而言, ...

  6. 过Hard题目.周末

      # Title Editorial Acceptance Difficulty Frequency   . 65 Valid Number     12.6% Hard    . 126 Word ...

  7. Java IO(二) 之 InputStream

    源代码均以JDK1.8作为參考 前言: InputStream实现了两个接口Closeable和AutoCloseable: Closeable:JDK1.5中引入,Closeable接口中仅仅有一个 ...

  8. java 基本类型、包装类、字符串之间的转换

    1.基本类型和包装类 基本类型和包装类可通过自动装箱和拆箱实现. int i = 24; Integer a = new Integer(i); //手动装箱 Integer b = i; //自动装 ...

  9. ural 1989(树状数组+多项式hash)

    题意:给出一个字符串.有两种操作,一个是p a b,问字符串从位置a到位置b的子串是否是一个回文子串.还有一个操作 c a b,把字符串位置a的字符替换为b. 题解:由于字符串长度为1e5且问的次数也 ...

  10. TCO14 1B L3: EagleInZoo, dp,tree

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=13117&rd=15950 看到树,又是与节点有关,通常是d ...