数论 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的矩形的个数. ...
随机推荐
- [题解] 2038: [2009国家集训队]小Z的袜子(hose)
莫队,卡常数 题目地址 思路 设\(\text{Vis[i]}\)为元素\(\text{i}\)在区间\(\text{[L,R]}\)的出现次数 考虑区间\(\text{[L,R]}\)和元素\(\t ...
- Linux 桌面玩家指南:08. 使用 GCC 和 GNU Binutils 编写能在 x86 实模式运行的 16 位代码
特别说明:要在我的随笔后写评论的小伙伴们请注意了,我的博客开启了 MathJax 数学公式支持,MathJax 使用$标记数学公式的开始和结束.如果某条评论中出现了两个$,MathJax 会将两个$之 ...
- scrapy爬虫 快速入门
Scrapy 1. 简介 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络 ...
- 第4章 简单的C程序设计——选择结构程序设计
在顺序结构中,各语句是按自上而下的顺序执行的,执行完上一个语句就自动执行下一个语句,是无条件的,不必作任何判断.实际上,很多情况下,需要根据某个条件是否满足来决定是否执行指定的操作任务,或者从给定的两 ...
- PMBook - 以考PMP为项目,整理项目章程
一.以考PMP为项目,整理项目章程 二.PMBook 制定项目章程:输出 参考资料:<PMBook第六版> 作 者: Jackson0714 出 处:http://www.cnblogs. ...
- sklearn中的Pipeline
在将sklearn中的模型持久化时,使用sklearn.pipeline.Pipeline(steps, memory=None)将各个步骤串联起来可以很方便地保存模型. 例如,首先对数据进行了PCA ...
- 面试官: 说说看, 什么是 Hook (钩子) 线程以及应用场景?
文章首发自个人微信号: 小哈学Java 个人网站地址: https://www.exception.site/java-concurrency/java-concurrency-hook-thread ...
- WebPack引用Bootstrap 无法使用图标的结局方案
npm i https://github.com/iconic/open-iconic.git -D 因为boostrap的css里删除了图标 分开了 我们在引入个呵呵. 下载:npm i boot ...
- Spring Boot 1.5.x 基础学习示例
一.为啥要学Spring Boot? 今年从原来.Net Team“被”转到了Java Team开始了微服务开发的工作,接触了Spring Boot这个新瓶装旧酒的技术,也初步了解了微服务架构.Spr ...
- 【工利其器】必会工具之(一)Source Insight篇
前言 “Source Insight(以下简称SI)是世界上最好的编辑器”,说这句话不知道会不会出门被打呢?-_- 中国古话说得好,“文无第一,武无第二”,所以不敢说SI是最好的,但是 ...