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的更多相关文章

  1. LightOJ 1341 唯一分解定理

    Aladdin and the Flying Carpet Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld &a ...

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

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

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

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

  4. LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria

    题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...

  5. LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...

  6. LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解

    http://www.lightoj.com/volume_showproblem.php?problem=1341 题意:给你长方形的面积a,边最小为b,问有几种情况. 思路:对a进行素因子分解,再 ...

  7. LightOJ 1341 - Aladdin and the Flying Carpet

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你地毯面积和最小可能边的长度,让你求有几种组合的可能. 题解:这题就厉害 ...

  8. LightOJ 1341 Aladdin and the Flying Carpet【整数分解】

    题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1341 题意: 给定一个数,将其拆分成两个数的乘 ...

  9. LightOJ 1341 Aladdin and the Flying Carpet 数学

    题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...

随机推荐

  1. 同台服务器 部署多个tomcat 需要做的修改

    需要修改以下加粗部分: 1:访问端口 8080->8081 2:shutdown 端口 8005->8015 3: AJP端口 8001->8010 <?xml version ...

  2. 【Linux 运维】 Centos7.x 系统修复模式

    一.linux的运行级别: 运行级别就是来确定系统启动时到底启动那个服务. linux默认有7个运行级别: 0 关机 1 单用户模式,用于系统修复 2 不完全的命令模式,不含NFS服务 3 完全的命令 ...

  3. 浪在ACM新春大作战

    题目链接: # Name 补题状态 A Memory and Crow 已补 B Memory and Trident 已补 C Memory and De-Evolution 已补 D Memory ...

  4. ElasticSearch 2.0以后的改动导致旧的资料和书籍需要订正的部分

    id原先是可以通过path指定字段的 "thread": { "_id" : { "path" : "thread_id" ...

  5. 局部加权回归(LWR) Matlab模板

    将百度文库上一份局部加权回归的代码,将其改为模板以便复用. q2x,q2y为数据集,是n*1的矩阵: r是波长参数,就是对于距离的惩罚力度: q_x是要拟合的数据横坐标,是1*n的矩阵: 得到的q_y ...

  6. tomcat端口号修改

    修改Tomcat的端口号: 在默认情况下,tomcat的端口是8080,如果出现8080端口号冲突,用如下方法可以修改Tomcat的端口号: 首先: 在Tomcat的根(安装)目录下,有一个conf文 ...

  7. eg_2

    2. 编写一个程序,输出在一个字符串中,指定的字符串出现的次数 第一种方法: public class Test { public static void main(String[] args) { ...

  8. lintcode-36-翻转链表 II

    36-翻转链表 II 翻转链表中第m个节点到第n个节点的部分 注意事项 m,n满足1 ≤ m ≤ n ≤ 链表长度 样例 给出链表1->2->3->4->5->null, ...

  9. LintCode-12.带最小值操作的栈

    带最小值操作的栈 实现一个带有取最小值min方法的栈,min方法将返回当前栈中的最小值. 你实现的栈将支持push,pop 和 min 操作,所有操作要求都在O(1)时间内完成. 注意事项 如果堆栈中 ...

  10. git & configs

    git & configs https://alvinalexander.com/git/git-show-change-username-email-address https://stac ...