题意

给一对数字 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的更多相关文章

  1. LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理

    题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet    PDF (English) S ...

  2. LightOJ-1341 Aladdin and the Flying Carpet 分解质因数(注意对大素数的优化)

    题目链接:https://cn.vjudge.net/problem/LightOJ-1341 题意 给出一个长方形的面积a 让你算整数边长的可能取值,并且两个边都大于给定数字b 思路 唯一分解定理: ...

  3. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  4. Aladdin and the Flying Carpet

    Aladdin and the Flying Carpet https://cn.vjudge.net/contest/288520#problem/C It's said that Aladdin ...

  5. C - Aladdin and the Flying Carpet 有多少种长方形满足面积为a(<=10^12),且最短边>=b;长方形边长为整数,且一定不可以是正方形。

    /** 题目:C - Aladdin and the Flying Carpet 链接:https://vjudge.net/contest/154246#problem/C 题意:有多少种长方形满足 ...

  6. Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】

    Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...

  7. 数论 C - Aladdin and the Flying Carpet

    It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...

  8. E - Aladdin and the Flying Carpet

    It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...

  9. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

随机推荐

  1. PHP判断SQL语句是否合法:mysqli_error()

    假设现在有条update语句,有时候update语句正确,但是受影响的行数是0. 那么怎么判断这条SQL语句到底是否正确?使用 mysqli_error($Conn); create table us ...

  2. 微信小程序Md5加密(utf-8汉字无影响)

    微信小程序不让使用第三方jqMD5 只好改原生js咯 废话不多说直接贴代码 其实就是将原生function调用改为 module.exports = md5; 文中 红色标注 使用方法 将md5.js ...

  3. 基于JDK1.8的ArrayList剖析

    前言 本文是基于JDK1.8的ArrayList进行分析的.本文大概从以下几个方面来分析ArrayList这个数据结构 构造方法 add方法 扩容 remove方法 (一)构造方法 /** * Con ...

  4. Python常用数据结构之collections模块

    Python数据结构常用模块:collections.heapq.operator.itertools collections collections是日常工作中的重点.高频模块,常用类型由: 计数器 ...

  5. .net core 2.0学习笔记(二):部署到Windows和Liunx系统

    .Net Core最大的亮点就是跨平台了,下面介绍下在Windows下和Liunx下的部署. 首先发布项目文件,点击网站项目右键 发布: 从下图发布的文件图片可以看出,不像以前bin目录下有很多dll ...

  6. 17_8_9 Spring 注入

    1 Spring 的 Bean 的属性注入: 构造方法的方式注入属性: <!-- 第一种:构造方法的方式 --> <bean id="car" class=&qu ...

  7. Python中List和Tuple类型

    a = 'python' print('hello,', a or 'world') b = '' print ('hello,', b or 'world') print('------------ ...

  8. the c programing language 学习过程6

    payroll工资名单 hierarchy分层层次 vexing 使人烦恼的 alignment结盟 semantics 语义 aethetic审美 parameterize 参数化 1结构标记 成员 ...

  9. Luogu P1092 虫食算

    题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简单的例子: 43#9865#045 +8468#6633 44445509678 其中# ...

  10. hive:框架理解

    1. 什么是hive  •Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能. •本质是将HQL转换为MapReduce程序  2. 为什么 ...