poj 2649 Factovisors 对n!进行因数分解
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4431 | Accepted: 1086 |
Description
0! = 1
n! = n * (n-1)! (n > 0)
We say that a divides b if there exists an integer k such that
k*a = b
Input
Output
Sample Input
6 9
6 27
20 10000
20 100000
1000 1009
Sample Output
9 divides 6!
27 does not divide 6!
10000 divides 20!
100000 does not divide 20!
1009 does not divide 1000!
Source
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN=;
bool vis[MAXN+];
int prime[MAXN+];
int n,m,p;
vector<pair<int,int> > exp; void init()//素数筛选
{
memset(vis,,sizeof(vis));
p=;
for(int i=; i<=MAXN; ++i)
{
if(vis[i]==false)
prime[p++]=i;
for(int j=; j<p&&i*prime[j]<=MAXN; ++j)
vis[i*prime[j]]=true;
}
} bool check(int x,int y)//判断当前的素数,n是否有这么多个
{
int tmp=n,sum=;
while(tmp)
{
sum+=tmp/x;
tmp/=x;
}
return y<=sum;
} bool judge()
{
for(int i=; i<exp.size(); ++i)
if(!check(exp[i].first,exp[i].second))
return false;
return true;
} int main()
{
init();
while(scanf("%d%d",&n,&m)==)
{
if(m==)
{
printf("%d does not divide %d!\n",m,n);
continue;
}
exp.clear();
int t=m;
for(int i=; i<p&&prime[i]<=m; ++i)
if(m%prime[i]==)
{
int cnt=;
while(m%prime[i]==)
{
m/=prime[i];
++cnt;
}
exp.push_back(make_pair(prime[i],cnt));//m的素数个数与m的素数因子对应
}
if(m!=)
exp.push_back(make_pair(m,));
if(judge())
printf("%d divides %d!\n",t,n);
else
printf("%d does not divide %d!\n",t,n);
}
return ;
}
poj 2649 Factovisors 对n!进行因数分解的更多相关文章
- 从“n!末尾有多少个0”谈起
在学习循环控制结构的时候,我们经常会看到这样一道例题或习题.问n!末尾有多少个0?POJ 1401就是这样的一道题. [例1]Factorial (POJ 1401). Description The ...
- 数学#素数判定Miller_Rabin+大数因数分解Pollard_rho算法 POJ 1811&2429
素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: h ...
- POJ 1811 Prime Test (Rabin-Miller强伪素数测试 和Pollard-rho 因数分解)
题目链接 Description Given a big integer number, you are required to find out whether it's a prime numbe ...
- 【poj 2429】GCD & LCM Inverse (Miller-Rabin素数测试和Pollard_Rho_因数分解)
本题涉及的算法个人无法完全理解,在此提供两个比较好的参考. 原理 (后来又看了一下,其实这篇文章问题还是有的……有时间再搜集一下资料) 代码实现 #include <algorithm> ...
- poj 1811 Prime Test 大数素数测试+大数因子分解
Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 27129 Accepted: 6713 Case ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
随机推荐
- 【JDK】JDK源码分析-AbstractQueuedSynchronizer(1)
概述 前文「JDK源码分析-Lock&Condition」简要分析了 Lock 接口,它在 JDK 中的实现类主要是 ReentrantLock (可译为“重入锁”).ReentrantLoc ...
- WPF:Task与事件在下载同步界面中的应用
//设置一个下载事件类,可传输一个字符串 public class DownloadEventArgs:EventArgs { public string id { get; ...
- DesignPattern系列__10单例模式
单例模式介绍 单例模式,是为了确保在整个软件体统中,某个类对象只有一个实例,并且该类通常会提供一个对外获取该实例的public方法(静态方法). 比如日志.数据库连接池等对象,通常需要且只需要一个实例 ...
- python多线程同步实例分析
进程之间通信与线程同步是一个历久弥新的话题,对编程稍有了解应该都知道,但是细说又说不清.一方面除了工作中可能用的比较少,另一方面就是这些概念牵涉到的东西比较多,而且相对较深.网络编程,服务端编程,并发 ...
- Netty学习(一)-为什么选择Netty
前面我们简单学习了NIO.我们知道java的I/O模型一共有四种,分别是:传统的BIO,伪异步I/O,NIO和AIO.为了澄清概念和分清区别,我们还是先简单的介绍一下他们的概念,然后再去比较优劣.以及 ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十三)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- Android常用库源码解析
图片加载框架比较 共同优点 都对多级缓存.线程池.缓存算法做了处理 自适应程度高,根据系统性能初始化缓存配置.系统信息变更后动态调整策略.比如根据 CPU 核数确定最大并发数,根据可用内存确定内存缓存 ...
- ASP.NET Core on K8S深入学习(5)Rolling Update
本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 一.什么是Rolling Update? 为了服务升级过程中提供可持续的不中断 ...
- 部分APP无法代理抓包的原因及解决方法
引言 HTTP应用层的抓包已经成为日常工作测试与调试中的重要一环,最近接触新项目突然之间发现之前的抓包手段都不好使了,顿时模块与模块之间的前端与服务之间的交互都变成了不可见,整个人都好像被蒙住了眼睛. ...
- Element-UI 2.4.11 版本 使用注意(发现一点更新一点)
1.$Vue.$refs.addForm.resetFields() 的resetFields()方法重置到默认值并不是 ,你在form绑定对象上写的默认值 ,而是这个form被渲染出来之后第一次赋到 ...