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) ...
随机推荐
- Vuejs 基础与语法
Vue 实例 创建第一个实例 {{}} 被称之为插值表达式.可以用来进行文本插值. <!DOCTYPE html> <html lang="en"> < ...
- Paper Reading - Show, Attend and Tell: Neural Image Caption Generation with Visual Attention ( ICML 2015 )
Link of the Paper: https://arxiv.org/pdf/1502.03044.pdf Main Points: Encoder-Decoder Framework: Enco ...
- matlab 常用集合相关的函数
Matlab常用的集合相关的函数如下: union(A,B) %求集合A和集合B的并集 intersect(A,B) %求集合A和集合 ...
- [leetcode-667-Beautiful Arrangement II]
Given two integers n and k, you need to construct a list which contains n different positive integer ...
- POJ 1679 The Unique MST(最小生成树)
Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...
- HTML5 canvas制作童年的回忆大风车
今天看到一篇CSS3写的大风车http://www.cnblogs.com/yaojaa/archive/2013/01/30/2882521.html,感觉CSS3太神奇了,这在以前用CSS是想都不 ...
- 关于GenericJDBCException的问题
在spring和hibernate整合的初步阶段,还没有编辑hibernate.cfg.xml这个文件,只有一个beans.xml文件.此时遇到了一个bug. Exception in thread ...
- 关于PHP使用GD库生成的验证码无法在别处显示
https://segmentfault.com/q/1010000002522270
- JS高级 1
关于string,number是大写,那么就是构造函数,变量不可能为null值,除非手动设置,要解除对象的引用的时候手动去除. in关键字操作数组的时候操作的是索引值,不是里面的内容,.在操作对象的时 ...
- java 基本--数据类型转换--001
小可转大,大转小可能会损失精度(编译出错,需要强制转换)A: byte,short,char -> int -> long -> float ->doubleB: byte,s ...