LightOJ1341 Aladdin and the Flying Carpet
题意
给一对数字 a,b ,a是一个长方形的面积,问有多少种整数的边的组合可以组成面积为a的长方形,要求最短的边不得小于b
数据组数T<=4000, a,b<=10^12
Solution
暴力求肯定TLE
想想唯一分解定理:
\(X=\Pi_i^{P_i|X} P_i^{a_i}\)
则X的正因数个数为\(\Pi_i(a_i + 1)\)
因为题目中要求的是长方形,且最短边大于b
那么a / b < b时输出0就好,否则将A分解,求出它的约数个数。
又因为求出来的约数对数是无序的,所以要除以2,最后枚举b以内的减去就好
然而\(b<=\sqrt a,10^6*T好像会TLE,但是过了???\)
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e5 + 10), __(1e6 + 10);
IL ll Read(){
char c = '%'; ll x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
}
int prime[__], isprime[__], num;
ll a, b, ans;
IL void Prepare(){
for(RG int i = 2; i <= __; ++i){
if(!isprime[i]) prime[++num] = i;
for(RG int j = 1; j <= num && i * prime[j] <= __; ++j){
isprime[i * prime[j]] = 1;
if(!(i % prime[j])) break;
}
}
}
int main(RG int argc, RG char *argv[]){
Prepare();
for(RG int T = Read(), i = 1; i <= T; ++i){
a = Read(); b = Read(); ans = 1;
if(a / b < b) ans = 0;
else{
RG ll x = a;
for(RG int j = 1; j <= num && prime[j] * prime[j] <= x; ++j){
if(x % prime[j]) continue;
RG ll cnt = 0;
while(!(x % prime[j])) ++cnt, x /= prime[j];
ans *= cnt + 1;
}
if(x > 1) ans *= 2;
ans >>= 1;
for(RG int i = 1; i < b; ++i) if(a % i == 0) --ans;
}
printf("Case %d: %lld\n", i, ans);
}
return 0;
}
LightOJ1341 Aladdin and the Flying Carpet的更多相关文章
- LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理
题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet PDF (English) S ...
- LightOJ-1341 Aladdin and the Flying Carpet 分解质因数(注意对大素数的优化)
题目链接:https://cn.vjudge.net/problem/LightOJ-1341 题意 给出一个长方形的面积a 让你算整数边长的可能取值,并且两个边都大于给定数字b 思路 唯一分解定理: ...
- 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 题意:有多少种长方形满足 ...
- 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 ...
- 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 (算数基本定理(唯一分解定理))
题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...
随机推荐
- JSP基础使用
一.JSP简介 JSP(Java Sever Pages):是为了能让 Java 在 Web 页面运行的一种语言. 在JSP中包括两种主要内容: 1. HTML.JS语言(静态内容).由客户端浏览器负 ...
- dedecms data文件夹外迁
出于网站安全考虑,我们一般要把data文件夹迁移到网站根目录外面. dedecms data文件夹外迁方法: 1. 修改首页文件中配置文件路径 打开/index.php,把代码 if(!file_ex ...
- 机器学习03:K近邻算法
本文来自同步博客. P.S. 不知道怎么显示数学公式以及排版文章.所以如果觉得文章下面格式乱的话请自行跳转到上述链接.后续我将不再对数学公式进行截图,毕竟行内公式截图的话排版会很乱.看原博客地址会有更 ...
- 💈 A Cross-Thread Call Helper Class
Conmajia © 2012, 2018 Introduction When you are working on background threads and call frontend GUI ...
- 使用Ajax发送http请求(get&post请求)
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. 同步和异步 同步和异步的概念 同步:必须等待前面的任务完成,才能继续后面 ...
- Linux进程作业常用命令
从鸟哥的私房菜书里摘抄的部分,方便查阅 一.作业管理 1.直接将命令放到后台执行的& 如想将/etc 备份为/tmp/ect.tar.gz时不想等待,可以这样做: ...
- vim+makefile入门编辑,编译,差错实例
vim+makefile入门编辑,编译,差错实例 vim makefile 编译 编写代码,一般在vim中编辑完后,输入:wq,在命令行下输入g++ hello.cc -o hello ,出现问题,打 ...
- Spring实现无需注解实现自动注入
xml配置 过程:设置自动装配的包-->使用include-filter过滤type选择为regex为正则表达式-->expression是表达是式也就是限制条件 <?xml ver ...
- Nginx的gzip压缩的原理和设置参数
开启Nginx gzip压缩非常简单,达到的效果可以压缩静态文件大小.提高页面访问速度.节省流量和带宽是很有帮助的,也为用户省去了很多流量:唯一的不足就是开启之后服务器这边会增加运算,进行压缩运算处理 ...
- UVA1374 IDA*
我刚开始的思路就是:用启发函数max * pow(2 , maxd - d) < n直接去判断,两个for循环往数组延伸,找到n为止,可是速度太慢.刘汝佳大哥说的直接使用新延伸出来的数,这样确实 ...