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

标签:入门讲座题解 数论


题目描述

  1. It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.
  2. Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin's uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.
  3. Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there can be two types of carpets and their sides are: {2, 6} and {3, 4}.

Input

  1. Input starts with an integer T (≤ 4000), denoting the number of test cases.
  2. Each case starts with a line containing two integers: a b (1 b a 1012) where a denotes the area of the carpet and b denotes the minimum possible side of the carpet.

Output

  1. For each case, print the case number and the number of possible carpets.

Sample Input

  1. 2
  2. 10 2
  3. 12 2

Sample Output

  1. Case 1: 1
  2. Case 2: 2

题意

给定\(a, b\), \(a\)


解析


通过代码

  1. /*
  2. Problem
  3. LightOJ - 1341
  4. Status
  5. Accepted
  6. Time
  7. 359ms
  8. Memory
  9. 6968kB
  10. Length
  11. 1607
  12. Lang
  13. C++
  14. Submitted
  15. 2019-11-25 21:51:33
  16. RemoteRunId
  17. 1640797
  18. */
  19. #include <bits/stdc++.h>
  20. using namespace std;
  21. typedef long long ll;
  22. const int MAXN = 1e6 + 50;
  23. bool vis[MAXN];
  24. int prime[MAXN], cnt = 0;
  25. inline ll read() //快读,加快程序输入速度.
  26. {
  27. ll res = 0;
  28. char ch;
  29. ch = getchar();
  30. while(!isdigit(ch))
  31. ch = getchar();
  32. while(isdigit(ch)){
  33. res = (res << 3) + (res << 1) + ch - 48;
  34. ch = getchar();
  35. }
  36. return res;
  37. }
  38. void get_prime() //欧拉筛,先找到sqrt(n)以内的质数,方便之后质因数分解.
  39. {
  40. vis[1] = 1;
  41. for(int i = 2; i <= int(1e6 + 5); i ++){
  42. if(!vis[i])
  43. prime[++ cnt] = i;
  44. for(int j = 1; j <= cnt && i * prime[j] <= int(1e6 + 5); j ++){
  45. vis[i * prime[j]] = 1;
  46. if(i % prime[j] == 0)
  47. break;
  48. }
  49. }
  50. return ;
  51. }
  52. int main()
  53. {
  54. get_prime();
  55. int times, _case = 0;
  56. scanf("%d", &times);
  57. while(times --){
  58. ll a, b, t;
  59. ll ans = 1;
  60. a = read(), b = read();
  61. t = a;
  62. if(b * b >= a){ //如果最小的因数都超过了sqrt(a),那么说明不存在符合条件的成对的因数了.
  63. printf("Case %d: 0\n", ++_case);
  64. continue;
  65. }
  66. for(int i = 1; i <= cnt && 1ll * prime[i] * prime[i] <= a; i ++){
  67. if(a % prime[i] == 0){
  68. int res = 0;
  69. while(a % prime[i] == 0){
  70. res ++;
  71. a /= prime[i];
  72. }
  73. ans *= 1ll * (res + 1);
  74. }
  75. }
  76. if(a > 1)
  77. ans <<= 1;
  78. ans >>= 1; //问有几对,两个因数算作一对.(如果是完全平方数的sqrt(a)因子,则不能算作一对.)
  79. for(ll i = 1; i < b; i ++){
  80. if(t % i == 0)
  81. ans --;
  82. }
  83. printf("Case %d: %lld\n", ++ _case, ans);
  84. }
  85. return 0;
  86. }

Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】的更多相关文章

  1. Aladdin and the Flying Carpet LightOJ 1341 唯一分解定理

    题意:给出a,b,问有多少种长方形满足面积为a,最短边>=b? 首先简单讲一下唯一分解定理. 唯一分解定理:任何一个自然数N,都可以满足:,pi是质数. 且N的正因子个数为(1+a1)*(1+a ...

  2. Aladdin and the Flying Carpet LightOJ - 1341 (素数打表 + 算术基本定理)

    题意: 就是求a的因数中大于b的有几对 解析: 先把素数打表 运用算术基本定理 求出a的所有因数的个数 然后减去小于b的因数的个数 代码如下: #include <iostream> #i ...

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

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

  4. LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理

    题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet    PDF (English) S ...

  5. Aladdin and the Flying Carpet

    Aladdin and the Flying Carpet https://cn.vjudge.net/contest/288520#problem/C It's said that Aladdin ...

  6. C - Aladdin and the Flying Carpet 有多少种长方形满足面积为a(<=10^12),且最短边>=b;长方形边长为整数,且一定不可以是正方形。

    /** 题目:C - Aladdin and the Flying Carpet 链接:https://vjudge.net/contest/154246#problem/C 题意:有多少种长方形满足 ...

  7. LightOJ 1341 - Aladdin and the Flying Carpet

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

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

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

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

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

随机推荐

  1. 建造者模式-C#改良实现

    区分网上已有的一般建造者模式实现,个人觉得实现太单一了,自己google查了一些好的实现,挑了其中比较适合的,做个笔记. # region 标准Builder模式实现 // 产品 class Tele ...

  2. LinkedHashMap源码学习

    描述 可以按照添加元素的顺序对元素进行迭代的HashMap的子类. 注意,上面说的是加元素的顺序.也就是说,更新元素时,是不会影响遍历结构的的.除非设置参数accessOrder为true,将更新元素 ...

  3. C lang: The Command line

    Ax_command line h Ax_a command line describe The command line is in enviroment for DOS,to user opera ...

  4. 内存取证工具-volatility、foremost

    内存取证 1. 内存取证工具volatility 猜测dump文件的profile值 root@kali:~/CTF# volatility -f mem.vmem imageinfo Volatil ...

  5. Flutter 快速上手定时器/倒计时及实战讲解

    本文微信公众号「AndroidTraveler」首发. 今天给大家讲讲 Flutter 里面定时器/倒计时的实现. 一般有两种场景: 我只需要你在指定时间结束后回调告诉我.回调只需要一次. 我需要你在 ...

  6. RMAN命令详解和常用汇总

    RMAN命令详解和常用汇总转摘汇集,日后使用本文链接:https://blog.csdn.net/EVISWANG/article/details/50448370http://blog.itpub. ...

  7. MySQL数据库~~~~~存储引擎

    1. InnoDB InnoDB引擎特点: 1.支持事务:支持4个事务隔离界别,支持多版本读. 2.行级锁定(更新时一般是锁定当前行):通过索引实现,全表扫描仍然会是表锁,注意间隙锁的影响. 3.读写 ...

  8. 你真的理解Java 注解吗?

    你真的理解Java 注解吗? 1.什么是注解? 官方解释: Java 注解用于为 Java 代码提供元数据.作为元数据,注解不直接影响你的代码执行,但也有一些类型的注解实际上可以用于这一目的.Java ...

  9. acwing 851. spfa求最短路 模板

    地址 https://www.acwing.com/problem/content/description/853/ 给定一个n个点m条边的有向图,图中可能存在重边和自环, 边权可能为负数. 请你求出 ...

  10. LeetCode 771: 宝石与石头 Jewels and Stones

    题目: 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. You're given strings ...