lightoj 1341
lightoj 1341 Aladdin and the Flying Carpet
链接:http://lightoj.com/volume_showproblem.php?problem=1341
题意:给定整数 a, b ,求 区间[b, a] 内的 a 的约数对的个数,a 的约数对(比如[2, 3] 与 [3, 2] 是同一对),也就是说前因子要小于后因子。
思路:我的思路比较直接,就是求 a 的约数的个数(用欧拉函数),除以 2 就得到约数对数, 然后暴力求解区间 [1, b] 内的 a 的约数。最后两数相减得到结果。
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <math.h>
using namespace std; typedef long long LL;
const int maxv = ;
bool nu[maxv];
int phi[], k; void prime() //素数表
{
memset(nu, , sizeof(nu));
int i, j;
k = ;
nu[] = , phi[] = ;
for(i = ; i < maxv; i += )
{
if(!nu[i]) phi[k++] = i;
for(j = ; j < k && i * phi[j] < maxv; j++)
{
nu[i*phi[j]] = ;
if(!(i % phi[j])) break;
}
}
} LL gain_ans(LL a) //得到区间[1, a] 的约数对数
{
int i = , j;
LL s = ;
if(a == ) return ;
while(phi[i] < a && i < k ) //欧拉函数
{
j = ;
if(a % phi[i] == )
while(a % phi[i] == )
a /= phi[i], j++;
s *= (j+);
i++;
}
if(a != ) s *= ;
return s / ;
} int main()
{
LL b, a, s, q;
int t, cs = ;
prime();
freopen("lightoj1341.txt", "r", stdin);
cin >> t;
while(t--)
{
scanf("%lld%lld", &a, &b);
q = ;
if(b >= sqrt(a)) s = ; // b 大小限定
else
{
q = ;
for(int i = ; i < b; ++i) //暴力枚举 [1, b] 的a 的约数
if(a % i == ) q++;
s = gain_ans(a) - q;
}
printf("Case %d: %lld\n", cs++, s);
}
return ;
}
lightoj 1341的更多相关文章
- LightOJ 1341 唯一分解定理
Aladdin and the Flying Carpet Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld &a ...
- 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 (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...
- LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria
题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...
- LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...
- LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解
http://www.lightoj.com/volume_showproblem.php?problem=1341 题意:给你长方形的面积a,边最小为b,问有几种情况. 思路:对a进行素因子分解,再 ...
- LightOJ 1341 - Aladdin and the Flying Carpet
题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你地毯面积和最小可能边的长度,让你求有几种组合的可能. 题解:这题就厉害 ...
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1341 题意: 给定一个数,将其拆分成两个数的乘 ...
- LightOJ 1341 Aladdin and the Flying Carpet 数学
题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...
随机推荐
- Office 365 E3功能
本文简要总结了Office 365E3的功能
- poj 2155 (二维树状数组 区间修改 求某点值)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33682 Accepted: 12194 Descript ...
- php多进程单例模式下的 MySQL及Redis连接错误修复
前几天写了个php常驻脚本,主要逻辑如下 //跑完数据后休息60秒 $sleepTime = 60; $maxWorker = 10; while (true) { $htmlModel = new ...
- 面试中要注意的 3 个 JavaScript 问题
JavaScript 是 所有现代浏览器 的官方语言.因此,各种语言的开发者面试中都会遇到 JavaScript 问题. 本文不讲最新的 JavaScript 库,通用开发实践,或任何新的 ES6 函 ...
- ServletContext域对象
场景:假设某个web服务,有两个servlet分别是servlet1和servlet2,servlet1要传参数name=zhangsan传送给servlet2,传统方法如下: servlet1端:用 ...
- Java容器之Iterator接口
Iterator 接口: 1. 所有实现了Collection接口的容器类都有一个iterator方法用以返回一个实现了Iterator接口的对象. 2. Iterator 对象称作迭代器,用以方便的 ...
- LintCode-66.二叉树的前序遍历
二叉树的前序遍历 给出一棵二叉树,返回其节点值的前序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 返回 [1,2,3]. 挑战 你能使用非递归实现么? 标签 递归 二叉树 二叉树遍历 非递归 c ...
- OSG学习:矩阵变换节点示例
#include<osgViewer\Viewer> #include<osg\Node> #include<osg\Geode> #include<osg\ ...
- Java设计
重构前 CustomDataChar | getConnection()findCustomers()createChar()displayChar() 重构后 CustomDataChar | da ...
- Activiti5工作流笔记二
流程变量 import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.activiti ...