BNUOJ -- The Turanga Leela Problem
题目大意:求两个数同余的模的个数。
思路分析:
同余定义: 设m是正整数,若a和b是正整数,且m|(a-b),则称a和b模m同余。
那么,由同余的定义可知,如果a和b的差能被m整除,则m就是a b 同余的模,进而也就是a b的因子。
先进行素数筛选,在进行差对素数试除,得到差的因子,也可以直接对所有可能的因数进行试除。
代码分别如下:
筛素数:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100000;
int prime[maxn/3];
int flag[maxn];
int cnt;
void Prime(){cnt=0;memset(flag,0,sizeof(flag));for(int i=2;i<maxn;i++){if(!flag[i])prime[cnt++]=i;for(int j=0;i*prime[j]<maxn;j++){flag[i*prime[j]]=1;if(i%prime[j]==0)break;}}
}
void f(int n){int ans=n;int ans1=1;for(int i=0;i<cnt&&n>1;i++){int cnt1=0;while(n%prime[i]==0){n/=prime[i];cnt1++;}ans1*=(cnt1+1);}if(n>1) ans1*=2;printf("%d\n",ans1);
}
int main(){int a,b;Prime();while(scanf("%d%d",&a,&b)==2){if(a==0&&b==0)break;int cnt=0;if(a>b) swap(a,b);int n=b-a;f(n);}return 0;
}
直接试除:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int f(int n){int ans=1;for(int i=2;i<=(int)sqrt(n+0.5)&&n>1;i++){int cnt=0;while(n%i==0){n/=i;cnt++;}ans*=(cnt+1);}if(n>1) ans*=2;printf("%d\n",ans);
}
int main(){int a,b;while(scanf("%d%d",&a,&b)==2){if(a==0&&b==0)break;int cnt=0;if(a>b) swap(a,b);int n=b-a;f(n);}return 0;
}
BNUOJ -- The Turanga Leela Problem相关推荐
- UVA 12465 - The Turanga Leela Problem(求某个数的约数个数)
题目链接 算是 有公式把.一个数的可以化成,素数相乘的形式,约数个数 = 每个素数的次幂+1的乘积. 知道了这个,还有3个需要注意....我竟然错了9次...哭死了.... 注意 1 的情况特判. ...
- poj 3077 Rounders/bnuoj 3196 Rounders 解题报告
这道题我真的想说"呵呵"!为什么呢?不是因为它是水题,而是因为我在bnu上提交AC之后转而去poj(pku)上去提交,结果是CE!!!明明在bnu上有着"This pro ...
- linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.
所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...
- A + B Problem
1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...
- Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r
出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...
- #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)
题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...
- BNUOJ 52305 Around the World 树形dp
题目链接: https://www.bnuoj.com/v3/problem_show.php?pid=52305 Around the World Time Limit: 20000msMemory ...
- ADPRL - 近似动态规划和强化学习 - Note 3 - Stochastic Infinite Horizon Problem
Stochastic Infinite Horizon Problem 3.Stochastic Infinite Horizon Problem 定义3.1 无限范围的马尔可夫决策过程 (Marko ...
- ADPRL - 近似动态规划和强化学习 - Note 2 - Stochastic Finite Horizon Problem
2. Stochastic Finite Horizon Problem 在这一节中主要介绍了随机DP算法来解决不确定性下的有限地范围问题,如Denition 1.4所述,它被表述为一个组合优化问题. ...
最新文章
- 怎样构建中文文本标注工具?(附工具、代码、论文等资源)
- 7:MD5、圆形图片、动态换肤
- 安装mysql的rpm包报错_rpm包在centos6.5中安装mysql5.7初始化报错的处理办法
- VMware vSphere 6简单部署---VCSA( vCenter Server Appliance)部署
- CVPR 2022 3月7日论文速递(17 篇打包下载)涵盖 3D 目标检测、医学影像、图像去模糊、车道线检测等方向
- 使用在线编辑器创建 SAP UI5 项目并运行
- 无监督学习 k-means_无监督学习-第3部分
- Android官方开发文档Training系列课程中文版:通过NFC共享文件之发送文件到另一台设备
- LeetCode 167 两数之和 II - 输入有序数组
- VR全景可视化制作小程序功能模块源码v1.0.28
- 纺织名词术语(针织品部分)---疵点
- python 数据库模块_MySQl 数据库 之 python模块 pymysql 简单介绍
- 排序算法的总结与使用题型
- VRRP的基本配置(以H3C模拟器为例)
- Swift 5 UIStackView中添加自动换行的Label
- mysql 全库查询关键字_数据库查询语句关键字总结
- 小火狐进化_第34章 契约小火狐
- QComboBox下拉框样式
- 国内外知名的待办事项app有哪些
- vid在c语言中的作用,——PVID的作用及和VID的区别
热门文章
- 计算机信息的编码教案,信息编码教案
- TypeError {(intermediate value)(intermediate value)}.then is not a function
- 智能门锁 c语言程序,新型汽车智能门锁控制器的设计(附C语言程序)☆
- 设计院用engineercms搭建移动端小程序服务
- MySQL数据库 --- Java的JDBC编程
- 看完这篇文章,彻底解决Mediaplayer重复播放视频黑屏的问题
- 写国际会议论文和期刊的一些注意事项
- Android Annotations 配置
- 疯壳AI开源无人机中断(按键检测)
- 智能商贸java代码实现——学习笔记day02