数论 C - 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
这个题目很明显是唯一分解定理,但是如果你不知道唯一分解定理,那这个其实就有点难。
如果明白这个这个定理,那么这个题目就变得很容易了,这个题目就是运用了这个定理。
题目让你求一个数的分解形式有多少种,且分解成的最小的数要比给定数字大,
那不就是你求出有多少个正因数,然后除以2,这个求的就是对数。
然后减去不满足条件的。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e6;
int v[maxn],isp[maxn], m; void init1()
{
m = ;
memset(v, , sizeof(v));
for (int i = ; i < maxn; i++)
{
if (v[i] == )
{
isp[m++] = i;
v[i] = i;
}
for (int j = ; j < m; j++)
{
if (v[i]<isp[j] || i * isp[j]>maxn) break;
v[i*isp[j]] = isp[j];
}
}
} ll cont(ll x)
{
ll sum = ;
if (x == ) return ;
for(ll i=;i<m;i++)
{
ll num = ;
while(x%isp[i]==)
{
x /= isp[i];
num++;
}
sum *= num + ;
if (x == ) break;
}
if (x > ) sum *= ;
return sum;
} int main()
{
int t, cas = ;
init1();
cin >> t;
while(t--)
{
ll a, b;
cin >> a >> b;
if(b>=sqrt(a))
{
printf("Case %d: %d\n", ++cas, );
}
else
{
ll cnt = ;
for(ll i=;i<b;i++)
{
if (a%i == ) cnt++;
}
ll sum = cont(a) / ;
ll ans = sum - cnt;
printf("Case %d: %lld\n", ++cas, ans);
}
}
return ;
}
数论 C - Aladdin and the Flying Carpet的更多相关文章
- Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...
- 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 ...
- E - 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(数论)
题意 有一块矩形(也可能是正方形)的飞毯. 给定飞毯的面积\(n\)和最小可能的边长\(a\),求可能有多少种不同边长的飞毯.(\(1<=a<=n<=1e12\)) 如面积\(n=6 ...
- [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的矩形的个数. ...
随机推荐
- SqlServer 递归查询
--查询部门及下属部门列表 WITH TEMP --递归 AS (SELECT Id, Code, Name, ParentId FROM [dbo].[AspSysDepartments] --查询 ...
- Java枚举储存的一种索引实现方式
首先引入guava包(一个进行代码校验的工具类): <dependency> <groupId>com.google.guava</groupId> <art ...
- Image和Base64互相转换
base64介绍: Base64编码是从二进制到字符的过程,可用于在HTTP环境下传递较长的标识信息.例如,在Java Persistence系统Hibernate中,就采用了Base64来将一个较长 ...
- 版本控制工具——Git常用操作(下)
本文由云+社区发表 作者:工程师小熊 摘要:上一集我们一起入门学习了git的基本概念和git常用的操作,包括提交和同步代码.使用分支.出现代码冲突的解决办法.紧急保存现场和恢复现场的操作.学会以后已经 ...
- python ddt数据驱动(简化重复代码)
在接口自动化测试中,往往一个接口的用例需要考虑 正确的.错误的.异常的.边界值等诸多情况,然后你需要写很多个同样代码,参数不同的用例.如果测试接口很多,不但需要写大量的代码,测试数据和代码柔合在一起, ...
- electron开发客户端注意事项(兼开源个人知识管理工具“想学吗”)
窗口间通信的问题 electron窗口通信比nwjs要麻烦的多 electron分主进程和渲染进程,渲染进程又分主窗口的渲染进程和子窗口的渲染进程 主窗口的渲染进程给子窗口的渲染进程发消息 subWi ...
- Springboot 系列(十三)使用邮件服务
在我们这个时代,邮件服务不管是对于工作上的交流,还是平时的各种邮件通知,都是一个十分重要的存在.Java 从很早时候就可以通过 Java mail 支持邮件服务.Spring 更是对 Java mai ...
- Zuul之Filter详解
Zuul详解 官方文档:https://github.com/Netflix/zuul/wiki/How-it-Works Zuul的中心是一系列过滤器,能够在HTTP请求和响应的路由过程中执行一系列 ...
- Python二级-----------程序冲刺1
1. 仅使用 Python 基本语法,即不使用任何模块,编写 Python 程序计算下列数学表达式的结果并输出,小数点后保留3位. ...
- JS之BOMBOM!
什么是BOM? bom即browser object model 也就是浏览器对象模型,BOM由多个对象组成,其中代表浏览器窗口的window对象是BOM的顶层对象,其他对象都是该对象的子对象. 顶层 ...