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. 剑指offer-二叉搜索树的后序遍历序列23

    题目描述 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. class Solution: def Verif ...

  2. HTML5form表单的相关知识总结

    首先在介绍HTML5form表单的新增内容之前,我总结了一下HTML的form表单的内容. <!DOCTYPE html> <html lang="en"> ...

  3. 数据库索引(结合B-树和B+树)

    数据库索引,是数据库管理系统中一个排序的数据结构以协助快速查询.更新数据库表中数据.索引的实现通常使用B树及其变种B+树. 在数据之外,数据库系统还维护着满足特定查找算法的数据结构,这些数据结构以某种 ...

  4. lintcode-30-插入区间

    插入区间 给出一个 无重叠 的按照区间起始端点排序的区间列表. 在列表中插入一个新的区间,你要确保列表中的区间仍然有序且 不重叠 (如果有必要的话,可以合并区间). 样例 插入区间[2, 5] 到 [ ...

  5. "亿家App"问卷调查分析结果及心得体会

    一.问卷问题设计 调查背景:随着现代社会互联网的发展,基于家庭产生的服务项目也越来越多.为增加家庭之间的交流和互助,增加家庭内部.家庭与家庭之间的沟通互助,并利用互联网便捷交流的优势,使家庭在享受服务 ...

  6. 安装django 提示ImportError: No module named setuptools

    安装django前要先安装setuptools 先安装一些必要的包,否则会报错:Python build finished, but the necessary bits to build these ...

  7. ASP.NET MVC 多语言解决方案

    1:打开VS,新建ASP.NET MVC4项目 2:创建一个放本地化资源的文件夹并命名为"Language",右键选择添加新项,选择资源文件并命名为"Com" ...

  8. java基础--逻辑运算符-- 002

    1:int a = 10;int b = 20;boolean flag = (a == b) //falseboolean flag = (a = b) //报错,不兼容的类型 2: &, ...

  9. 苹果IOS、安卓推送功能开发

    IOS推送开发:以下是基于开源javapns推送开发1.DerInputStream.getLength(): lengthTag=111, too big.先排除是否由于打包时证书 .p12 文件被 ...

  10. CDN概念基本介绍

    CDN概念基本介绍 一 . CDN简介 什么是CDN? CDN的全称是Content Delivery Network,即内容分发网络. 其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的 ...