Light OJ 1341 Aladdin and the Flying Carpet
题意:求大于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的更多相关文章
- Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS
进入a b 多少努力p, q 使p*q == a && p < q && p >= b 直接大整数分解 然后dfs所有可能的解决方案劫持 #include ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
- LOJ 1341 Aladdin and the Flying Carpet(质因子分解)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给两个数a,b,求满足c * d = a且c>=b且d>=b的 ...
- [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))
题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...
- LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...
- 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 题意: 给定一个数,将其拆分成两个数的乘 ...
随机推荐
- 优动漫PAINT-樱花教程
很雅致清新的樱花教程~在很多地方都可以运用到哟~原文转载自优动漫官网. 想要Get到更多有关优动漫的信息包括软件下载,可关注http://www.dongmansoft.com.
- 系统出现0x0000006B蓝屏修复,系统文件损坏 bootcat.cache、driver.stl
系统蓝屏,无论如何都不能进入系统,所以你需要一个U盘启动器,就是能绕过电脑的系统进入电脑,可以用U盘做一个U盘启动器,或者其他方法均可以,只要能进入到你的电脑访问C盘即可 2 下载链接内的文件解压后放 ...
- 修改maven打包名字
仅需在pom.xml添加下列配置 build> <finalName>userapi</finalName> </build>
- 地图底图的类型——MapView,SceneView
MapView用于创建二维地图平面. 引用“esri/Map”,"esri/views/MapView" 具体做法并举例:var map = new Map({basemap:&q ...
- matlab Time-domain analysis 渐进式或者实时获取仿真值
首先准备一个传递函数sys, 然后使用lsim(sys,u,t,x0)函数(通用的时序分析的函数) u: The input u is an array having as many rows as ...
- [CTSC2016]单调上升路径
题目:UOJ#201. 题目大意:给定n个点(n是偶数)的完全图,现在要你给每条边确定一个权值(互不相等),使得最长的单调上升路径最短.现在要你输出边的权值. 一条路径被称为单调上升的,如果沿着它走时 ...
- MD5 加密原理(转)
MD5的全称是Message-Digest Algorithm 5(信息-摘要算法),在90年代初由MIT Laboratory for Computer Science和RSA Data Secur ...
- Java学习书目
Java学习书目 拜读了:http://www.importnew.com/26932.html#comment-636554
- Android Studio生成apk
1.菜单Build->Generate Signed APK 2.生成android.keystore,能够依据弹框去Create new一个,也可使用命令来生成android.keystore ...
- bzoj4873: [Shoi2017]寿司餐厅(最大权闭合子图)
4873: [Shoi2017]寿司餐厅 大难题啊啊!!! 题目:传送门 题解:一眼题是网络流,但还是不会OTZ,菜啊... %题解... 最大权闭合子图!!! 好的...开始花式建边: 1.对于每个 ...