Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】(未完成)
标签:入门讲座题解 数论
题目描述
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
题意
给定\(a, b\), \(a\)
解析
通过代码
/*
Problem
LightOJ - 1341
Status
Accepted
Time
359ms
Memory
6968kB
Length
1607
Lang
C++
Submitted
2019-11-25 21:51:33
RemoteRunId
1640797
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 50;
bool vis[MAXN];
int prime[MAXN], cnt = 0;
inline ll read() //快读,加快程序输入速度.
{
ll res = 0;
char ch;
ch = getchar();
while(!isdigit(ch))
ch = getchar();
while(isdigit(ch)){
res = (res << 3) + (res << 1) + ch - 48;
ch = getchar();
}
return res;
}
void get_prime() //欧拉筛,先找到sqrt(n)以内的质数,方便之后质因数分解.
{
vis[1] = 1;
for(int i = 2; i <= int(1e6 + 5); i ++){
if(!vis[i])
prime[++ cnt] = i;
for(int j = 1; j <= cnt && i * prime[j] <= int(1e6 + 5); j ++){
vis[i * prime[j]] = 1;
if(i % prime[j] == 0)
break;
}
}
return ;
}
int main()
{
get_prime();
int times, _case = 0;
scanf("%d", ×);
while(times --){
ll a, b, t;
ll ans = 1;
a = read(), b = read();
t = a;
if(b * b >= a){ //如果最小的因数都超过了sqrt(a),那么说明不存在符合条件的成对的因数了.
printf("Case %d: 0\n", ++_case);
continue;
}
for(int i = 1; i <= cnt && 1ll * prime[i] * prime[i] <= a; i ++){
if(a % prime[i] == 0){
int res = 0;
while(a % prime[i] == 0){
res ++;
a /= prime[i];
}
ans *= 1ll * (res + 1);
}
}
if(a > 1)
ans <<= 1;
ans >>= 1; //问有几对,两个因数算作一对.(如果是完全平方数的sqrt(a)因子,则不能算作一对.)
for(ll i = 1; i < b; i ++){
if(t % i == 0)
ans --;
}
printf("Case %d: %lld\n", ++ _case, ans);
}
return 0;
}
Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】的更多相关文章
- Aladdin and the Flying Carpet LightOJ 1341 唯一分解定理
题意:给出a,b,问有多少种长方形满足面积为a,最短边>=b? 首先简单讲一下唯一分解定理. 唯一分解定理:任何一个自然数N,都可以满足:,pi是质数. 且N的正因子个数为(1+a1)*(1+a ...
- Aladdin and the Flying Carpet LightOJ - 1341 (素数打表 + 算术基本定理)
题意: 就是求a的因数中大于b的有几对 解析: 先把素数打表 运用算术基本定理 求出a的所有因数的个数 然后减去小于b的因数的个数 代码如下: #include <iostream> #i ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- 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
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 题意:有多少种长方形满足 ...
- LightOJ 1341 - Aladdin and the Flying Carpet
题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你地毯面积和最小可能边的长度,让你求有几种组合的可能. 题解:这题就厉害 ...
- LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria
题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
随机推荐
- CAD制图软件哪个好?试试这两个就知道了
CAD中,每天都是需要绘制很多的CAD图纸.一般都是借助CAD制图软件来进行使用的,图纸的格式都是dwg格式的.那CAD制图工具有很多种,对于CAD制图初学入门的小伙伴们来说CAD制图软件哪个好?想要 ...
- Quartznet速记
参与 https://www.cnblogs.com/lzrabbit/archive/2012/04/14/2371420.html 1.XML配置 参考:https://www.cnblogs.c ...
- Oracle - crfclust.bdb文件太大
今天在检查oracle rac集群时,突然才发现服务器的根目录下面占用了很多空间,照道理不应该出现这种情况,初步猜想可能是哪个日志或跟踪文件太大导致.切换到跟目录,使用du -sh *来一层一层查看到 ...
- Unity3D VidoePlayer 加载StreamingAssets下视频
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;usi ...
- Java之Lambda表达式
函数式编程思想概述 面向对象过分强调“必须通过对象的形式来做事情”,而函数式思想则尽量忽略面向对象的复杂语法——强调做什么,而不是以什么形式做. 面向对象的思想: 做一件事情,找一个能解决这个事情的对 ...
- TopCoder12808 「SRM594Medium」FoxAndGo3 二分图最大独立集
问题描述 一个 \(N \times N\) 围棋棋盘,任意两个白子不相邻,你要加入若干个黑子并提出白子,最大化空格数目. submit 题解 显然最终棋盘的局面不能够一个白子和它周围的空格都是空的, ...
- 了解angularjs中的生命周期钩子函数$onInit,$onChange,$onDestory,$postLink
壹 ❀ 引 我在前面花了三篇文章用于介绍angularjs的指令directive,组件component,并专门花了一篇文章介绍directive与component的不同,其中提到在compon ...
- windowsServer---- 在iis 上安装网站
1.找到信息服务IIS 管理器如图: 2.进入后进行配置 3.添加本地网站 配置网站 如果域名没有解析的话,可以在添加一个 端口用于测试 点击浏览就行查看 如果报错 解决:找到目录浏览,并启动 点击 ...
- goweb-搭建服务
web应用简介 Web 应用在我们的生活中无处不在.看看我们日常使用的各个应用程序,它们要 么是 Web 应用,要么是移动 App 这类 Web 应用的变种.无论哪一种编程语言,只要 它能够开发出与人 ...
- Python菜鸟文本处理4种方法
自从认识了python这门语言,所有的事情好像变得容易了,作为小白,逗汁儿今天就为大家总结一下python的文本处理的一些小方法. 话不多说,代码撸起来. python大小写字符互换 在进行大小写互换 ...