题意

给一对数字 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. Access denied for user 'root'@'localhost' (using password: YES)的解决

    今天使用phpmyadmin登录远程数据库所以改了一些配置,结果回过头来登录本地mysql时来了一句mysql Access denied for user 'root'@'localhost' (u ...

  2. python学习:99乘法口诀

    #!/usr/bin/python   for i in xrange(1,10):     for j in xrange(1,i+1):         print "%s*%s=%s& ...

  3. ASP.NET CORE MVC 实现减号分隔(Kebab case)样式的 URL

    ASP.NET CORE MVC 中,默认的 Route 模板是: /{controller}/{action}  .我们可以通过开启 URL 小写转换将 URL 变为小写,但此方式在 Control ...

  4. Java Integer类型比较

    今天做了一道题目题目如下: Integer a=10; Integer b=10; System.out.print(a==b); Integer c=200; Integer d=200; Syst ...

  5. Activiti中的各个service的作用

    各个Service的作用: RepositoryService 管理流程定义 RuntimeService 执行管理,包括启动.推进.删除流程实例等操作 TaskService 任务管理 Histor ...

  6. JSTL的相关使用

    index.jsp <%@ page language="java" import="java.util.*" pageEncoding="UT ...

  7. 在windows上安装nginx

    在windows上安装nginx   最近自己也尝试了一下在windows上安装nginx,其实非常的简单,这里算是备忘一下.   首先需要到nginx的官网上下载最新版的nginx:http://n ...

  8. Java数字签名——DSA算法

    RSA数字加密算法参考:http://www.cnblogs.com/LexMoon/p/javaRSA.html DSS: 数字签名标准 DSA: 数字签名算法 DSA仅仅包含数字签名 —————— ...

  9. Node.js,commonjs,require

    环境: Node应用由模块组成,采用CommonJS模块规范. node的全局对象是global,没有window这个对象. process表示当前执行的进程,挂在global之下. CommonJS ...

  10. SCU 4438 Censor KMP/Hash

    题意:给定一个模式串和文本,要求删除所有模式串.可能删除后会形成新的模式串,必须全部删除. 思路1:kmp算法求得失配数组,用一个match数组记录文本串中第i字符和未删除的字符能匹配模式串的长度.这 ...