E - Aladdin and the Flying Carpet
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.
Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin's uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.
Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there can be two types of carpets and their sides are: {2, 6} and {3, 4}.
Input
Input starts with an integer T (≤ 4000), denoting the number of test cases.
Each case starts with a line containing two integers: a b (1 ≤ b ≤ a ≤ 1012) where a denotes the area of the carpet and b denotes the minimum possible side of the carpet.
Output
For each case, print the case number and the number of possible carpets.
Sample Input
2
10 2
12 2
Sample Output
Case 1: 1
Case 2: 2
题目大意 就是给你一个面积N和一个可能的最小边m,问你满足条件的组合有多少个(不能是正方形)
题解:先求出a的因子的个数,然后暴力求出小与b而且是a的因子的个数,然后再减去就行了。对于这个题,边的最小值为b,所以如果b*b>=a的话,那么一定无解。若有解那么b<=sqrt(a)所以b的范围要小于1e6,但是t的范围是4e3,时间复杂度大约是o(bt)=4e10。明显不行.....,但是百度上都这么做的,可能是数据有点水吧~。
using namespace std;
typedef long long ll;
const ll N=1e6+;
const ll MAX=1e6+;
bool primes[N];
ll pre[N];
ll pos=;
void inint(){
primes[]=;
primes[]=;
for(ll i=;i<=MAX;i++){
if(!primes[i]) pre[++pos]=i;
for(ll j=;j<=pos&&i*pre[j]<=MAX;j++){
primes[i*pre[j]]=;
if(i%pre[j]==) break;
}
}
}
void solve(ll time){
ll a,b;
scanf("%lld%lld",&a,&b);
ll m=a;
if(b*b>=a) {
printf("Case %d: 0\n",time);
return ;
}
ll ans=;
for(ll i=;i<=pos;i++){
if(pre[i]>a) break;
if(a%pre[i]==){
ll p=;
while(a%pre[i]==) {
a/=pre[i];p++;
}
ans*=((ll)+p);
}
}
if(a!=) ans*=(ll);
ans/=(ll);
for(ll i=;i<b;i++) if(m%i==) ans--;
printf("Case %d: %lld\n",time,ans);
}
int main(){
int t;
inint();
scanf("%d",&t);
for(int i=;i<=t;i++) solve(i);
return ;
}
E - Aladdin and the Flying Carpet的更多相关文章
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- Aladdin and the Flying Carpet
Aladdin and the Flying Carpet https://cn.vjudge.net/contest/288520#problem/C It's said that Aladdin ...
- C - Aladdin and the Flying Carpet 有多少种长方形满足面积为a(<=10^12),且最短边>=b;长方形边长为整数,且一定不可以是正方形。
/** 题目:C - Aladdin and the Flying Carpet 链接:https://vjudge.net/contest/154246#problem/C 题意:有多少种长方形满足 ...
- LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理
题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet PDF (English) S ...
- Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...
- 数论 C - Aladdin and the Flying Carpet
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...
- [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))
题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
- LightOJ 1341 Aladdin and the Flying Carpet 数学
题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...
随机推荐
- 【SQL SERVER重新认识】数据内部存储结构简单探索
数据库经常需要打交道,但是从来没想过数据库内部是如何存储数据. 今天探索一下数据库内部如何存储数据,从下面几个方面探索 数据库内部如何存储数据 索引数据如何存储 操作数据对存储影响 总结 数据库内部如 ...
- 热点 | github近期热点项目汇总
本文是近期Github热点项目的汇总,如果你想了解更多优秀的github项目,请关注我们公众号的github系列文章. 推荐 | 7个你最应该知道的机器学习相关github项目 热点 | 六月Gith ...
- ehcahe + redis 实现多级缓存
1,了解数据存储的位置的不同 数据库:存储在磁盘上 redis:存储在内存上 ehcache:应用内缓存 缓存的目的:是为了将数据从一个较慢的介质上读取出来,放到一个较快的介质上,为了下次读取的时候更 ...
- random方法
random.randint(1,10) # 产生 1 到 10 的一个整数型随机数 ,包括1和10random.random() # 产生 0 到 1 之间的随机浮点数rand ...
- Mac OSX安装 Django MySQL mysqlclient
Python3.6 $ brew install mysql-connector-c # 如果没有安装brew,先安装:# 安装可以查看:https://www.cnblogs.com/Jokergu ...
- 模块 shutil_zipfile_tarfile压缩解压
shutil_zipfile_tarfile压缩解压 shutil 模块 高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length]) #将 ...
- Java 为 Excel 中的行设置交替背景色
在制作Excel表格时,通过将数据表中上下相邻的两行用不同的背景色填充,可以使各行的数据看起来更清楚,避免看错行,同时也能增加Excel表格的美观度.本文将介绍如何在Java程序中为 Excel 奇数 ...
- C语言把整数转换为字符串
目录 1.把整数/长整数格式化输出到字符串 2.注意事项 3.版权声明 各位可能在网上看到用以下函数可以将整数转换为字符串: itoa(); //将整型值转换为字符串 ultoa(); // 将无符号 ...
- CCF2018 12 2题,小明终于到家了
最近在愁着备考,拿CCF刷题,就遇到这个难题,最后搜索了一下大佬们的方法,终于解决, 问题描述 一次放学的时候,小明已经规划好了自己回家的路线,并且能够预测经过各个路段的时间.同时,小明通过学校里安装 ...
- (C#、JavaScript)面向对象的程序设计
面向对象(OOP)的理解 喜欢程序的朋友们,大家应该都听过一句话"万物皆对象",感觉老牛X了. 面向对象的程序设计,它是围绕真实世界来设计程序的. 面向对象三要素:封装.继承.多态 ...