算数基本定理:

基本形式:(Pn表示质数)

导出结论(ACM中会用到的):

1.    (正因数个数)

2.    (正因数之和)

例题:

1341 - Aladdin and the Flying Carpet
    PDF (English) Statistics Forum
Time Limit: 3 second(s) Memory Limit: 32 MB

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.

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.

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

Input starts with an integer T (≤ 4000), denoting the number of test cases.

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

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

Sample Input

Output for Sample Input

2

10 2

12 2

Case 1: 1

Case 2: 2

题意:给出a,b找出[b,a]中乘积为a的因子对个数(例如a=10,b=2,则只存在因子对{2,5}符合条件)

利用算数基本定理1求得[1,a]中因子对(求出因子数除以2),在暴力求解[1,b]中因子对,相减即可。

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#define MAX 1000047
typedef long long ll;
using namespace std;
ll a,b,p[MAX],prime[MAX],m,ans,t,cnt=0;void init() //标记素数并保存到prime数组中
{m=0;memset(p,0,sizeof(p));for (ll i=2;i<=MAX;i++){if (!p[i]){prime[m++]=i; //保存到prime数组 for (ll j=i+i;j<=MAX;j+=i)p[j]=1;}}
}int main()
{init();scanf("%d",&t);while(t--){scanf("%lld%lld",&a,&b);if (b>=sqrt(a)) //类似剪枝(否则会超时) {printf("Case %d: 0\n",++cnt);continue;}ll i=0,suma=1,sumb=0,x=a;while(prime[i]<a&&i<m) //为{if (a%prime[i]==0) //是因子{ll an=0;while(a%prime[i]==0){a/=prime[i];an++;} //求出指数 suma*=(an+1);}i++;}if (a>1) suma*=2;for (ll i=1;i<=sqrt(b);i++)if (x%i==0) sumb++; //找出[1,b)中的因子 ans=suma/2-sumb; //求出的是因子个数,除以2就是因子对个数 printf("Case %d: %lld\n",++cnt,ans);}return 0;
}

核心代码:

1.求素数(详见https://blog.csdn.net/Radium_1209/article/details/80232925)

2.求各个指数

while(a%prime[i]==0)
{a/=prime[i];an++; //an即为所求指数
}

3.带入公式

suma*=(an+1);

转载于:https://www.cnblogs.com/Radium1209/p/10415371.html

算数基本定理(例题:LightOJ1341)相关推荐

  1. 数论 - 算数基本定理的运用 --- nefu 118 : n!后面有多少个0

    题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php Mean: 略. analyse: 刚开始想了半天都没想出来,数据这么大,难道是有什么公 ...

  2. 数论读书笔记——算数基本定理

    欧几里得: 欧几里得算法: 定理1:整数a≥b>0,令r0=a,r1=b如果我们做带余除法得到rj=r(j+1)q(j+1)+r(j+2),且0<r(j+2)<r(j+1),j=0, ...

  3. (5)因数分解与算数基本定理

    因数分解与算数基本定理 素数是这样的整数 p ≥ 2 p\geq2 p≥2,它的(正)因数仅有1与p.不是素数的整数 m ≥ 2 m\geq2 m≥2叫做合数.例如, 素 数 2 , 3 , 5 , ...

  4. nefu 118 n!后面有多少个0 算数基本定理,素数分解

    n!后面有多少个0 Time Limit 1000ms Memory Limit 65536K description 从输入中读取一个数n,求出n! 中末尾0的个数. input 输入有若干行.第一 ...

  5. 判断质数和用算数基本定理分解质因数

    文章目录 摘要 质数 判断一个数是否是质数 分解质因数 超级详细的基础算法和数据结构合集: https://blog.csdn.net/GD_ONE/article/details/104061907 ...

  6. 算数基本定理和代数基本定理

    算术基本定理可表述为:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积. 代数学基本定理:任何复系数一元n次多项式 方程在复数域上至少有一根(n≥1),由此推出,n次复 ...

  7. poj 1845 Sumdiv (算数基本定理+逆元)

    输入a和b,求a^b的所有因子之和. #include <iostream> #define ll long longusing namespace std;const int mod=9 ...

  8. 对 算术基本定理 的研究

    写在前面: 数论被誉为数学皇后,是研究整数性质的理论(好多人对数论的范围不清楚额) 而算术基本定理是数论中的重要定理 这篇文章是我对于算术基本定理的一些研究,研究的资料源自博客,百科,问答,持续更新 ...

  9. 永远不可能学会的数论之基础数论(例题)

    涉及到知识 1.普通筛选.埃拉托斯特尼筛选.欧拉筛选 Bi-shoe and Phi-shoe Bamboo Pole-vault is a massively popular sport in Xz ...

最新文章

  1. Psych101(part1)--Day1
  2. 原来医生的处方不是随便乱写的...
  3. ConcurrentHashMap--自用,非教学
  4. C++连接mysql及遇到的相关问题
  5. oracle数据库从入门到精通
  6. ubuntu sun-jdk
  7. mysql 修改root密码 修改账户登录host
  8. python程序设计实验报告答案大全_Python程序设计实验三
  9. spring mvc数据绑定与表单标签库
  10. 类和对象的关系练习题:需求:将汽车改装成3个轮子的车并换个颜色。
  11. 【苹果开发者账号】记一次苹果账号付款失败,报 未完成付款 的问题,全网都没解决办法!
  12. ubuntu 下安装 qq wechat VirtualBox notepadqq
  13. 记忆力训练软件测试自学,记忆力训练题,每天10分钟,一周提高5倍记忆力
  14. Python数据可视化交互基本
  15. [uoj30][CF Round #278]Tourists——树链剖分+圆方树
  16. Java 中 字符串 1234 怎么转成 int?
  17. 如何听节拍器_节拍器使用方法
  18. 01-MySQL 创建数据库
  19. ThreadPoolTaskExecutor 线程池的使用
  20. Workflow,要不要了解一下

热门文章

  1. 根据浏览器内核判断是web/iOS/android/ipad/iphone 来打开不同的网站或页面
  2. python相关概念
  3. java Math类中的pow方法的问题Math.pow(64,1/3)是1而不是4
  4. SDMemoryCache中的NSMapTable
  5. 看看HashSet源码
  6. Thrift RPC 系列教程(3)——模块化
  7. 对Mapreduce代码进行单元测试
  8. 《Photoshop Lightroom4 经典教程》—第2课2.2节切换屏幕模式
  9. 我之我见:samba共享
  10. ecshop 首页添加某个分类下面的商品