http://lightoj.com/volume_showproblem.php?problem=1341

题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数。

什么叫唯一分解定理:算术基本定理可表述为:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积N=P1a1P2a2P3a3......Pnan,这里P1<P2<P3......<Pn均为质数,其中指数ai是正整数。这样的分解称为 的标准分解式

我们求出n的因子个数之后,先除以2,得到一半的因子个数,然后从头开始循环到b不合格的直接减去

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. #include<algorithm>
  6. #include<iostream>
  7. #include<vector>
  8. #include <queue>
  9.  
  10. using namespace std;
  11. #define N 1001000
  12. #define ESP 1e-8
  13. #define INF 0x3f3f3f3f
  14. #define memset(a,b) memset(a,b,sizeof(a))
  15.  
  16. int prime[N], k, vis[N];
  17.  
  18. void Prime()
  19. {
  20. k=;
  21. memset(vis, );
  22. for(int i=; i<N; i++)
  23. {
  24. if(!vis[i])
  25. {
  26. prime[k++] = i;
  27. for(int j=i+i; j<N; j+=i)
  28. vis[j] = ;
  29. }
  30. }
  31. }///素数筛选
  32.  
  33. long long solve(long long n)
  34. {
  35. long long int sum = ;
  36.  
  37. for(int i=; i<k && prime[i]*prime[i]<=n; i++)
  38. {
  39. if(n%prime[i] == )
  40. {
  41. int ans=;
  42. while(n%prime[i] == )
  43. {
  44. ans++;
  45. n /= prime[i];
  46. }
  47. sum *= (+ans);
  48. }
  49. }
  50.  
  51. if(n>)
  52. sum *= ;
  53. return sum;
  54. }///求n得因子个数;
  55.  
  56. int main()
  57. {
  58. int T, t=;
  59. scanf("%d", &T);
  60. Prime();
  61. while(T --)
  62. {
  63. long long a,b;
  64. scanf("%lld %lld", &a, &b);
  65.  
  66. if(a <= b*b)
  67. {
  68. printf("Case %d: 0\n", t++);
  69. continue;
  70. }
  71.  
  72. long long int num = solve(a);
  73.  
  74. num /= ;
  75.  
  76. for(int i=; i<b; i++)
  77. {
  78. if(a % i == )
  79. num --;
  80. }
  81.  
  82. printf("Case %d: %lld\n", t++, num);
  83. }
  84. return ;
  85. }

1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)的更多相关文章

  1. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

  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. LOJ 1341 Aladdin and the Flying Carpet(质因子分解)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给两个数a,b,求满足c * d = a且c>=b且d>=b的 ...

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

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

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

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

  6. Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS

    进入a b 多少努力p, q 使p*q == a && p < q && p >= b 直接大整数分解 然后dfs所有可能的解决方案劫持 #include ...

  7. Light OJ 1341 Aladdin and the Flying Carpet

    题意:求大于b的a的因数对有几组.例10  2结果为{2,5},12 2结果为{2,6}{3,4}-----不反复 解一:分解质因数+DFS #include <iostream> #in ...

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

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

  9. LightOJ 1341 - Aladdin and the Flying Carpet

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

随机推荐

  1. ubuntu查看系统资源占用(内存,cpu和进程)

    ubuntu查看系统资源占用(内存,cpu和进程) 1  top 查看ubuntu的资源占用的命令为$: top    说明:top命令就可以查看内存,cpu和进程了,很方便 top: 主要参数 d: ...

  2. Permission denied:multiarray.cp35-win_amd64.pyd(tensorflow0.12.0在windows下安装)

    今天在windows下安装tensorflow0.12.0. 碰到一个奇怪的问题.Permission denied:multiarray.cp35-win_amd64.pyd 就是复制文件,一直复制 ...

  3. ---Linux 10 年的硕果累累啊!

    http://mt.sohu.com/20160128/n436204298.shtml

  4. python2.7版本win7 64位系统安装pandas注意事项_20161226

    经过卸载安装python几经折腾,参考了各种网站,终于安装成功. [成功的步骤] 保存这个python第三方库网站,网址是http://www.lfd.uci.edu/~gohlke/pythonli ...

  5. php用simplexml来操作xml

    <?php$username = 'zhansan';if (!file_exists('001.xml')){ $fp = fopen('001.xml', 'w'); $xmlContent ...

  6. javascript对象引用与赋值

    avascript对象引用与赋值 <script type="text/javascript"> //例子一: 引用 var myArrayRef = new Arra ...

  7. 关于设置anroid系统时间

    我最近在做一个项目需要设置android系统时间,设置android 时间往往缺少权限,看到http://blog.csdn.net/kakaxi1o1/article/details/3687278 ...

  8. 右键添加"用vim打开"文件选项

    保存一个foo.reg文件 ==================== Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\Shell\e ...

  9. SQL Server 导入数据失败:无法在只读列“Id”中插入数据

    解决方案: 在数据库导入"选择源表和源视图"->点击对应表后的“编辑映射”按钮->勾选“启用标识列插入”->导入即可.

  10. ZT 北大青鸟APTECH(南京泰思特)

    北大青鸟APTECH(南京泰思特)授权培训中心诚招 高级软件测试/开发培训讲师 Posted on 2008-01-14 11:38 追求卓越 阅读(590) 评论(7) 编辑 收藏 北京阿博泰克北大 ...