Factovisors
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4431   Accepted: 1086

Description

The factorial function, n! is defined thus for n a non-negative integer:

   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

The input to your program consists of several lines, each containing two non-negative integers, n and m, both less than 2^31.

Output

For each input line, output a line stating whether or not m divides n!, in the format shown below.

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!进行因数分解的更多相关文章

  1. 从“n!末尾有多少个0”谈起

    在学习循环控制结构的时候,我们经常会看到这样一道例题或习题.问n!末尾有多少个0?POJ 1401就是这样的一道题. [例1]Factorial (POJ 1401). Description The ...

  2. 数学#素数判定Miller_Rabin+大数因数分解Pollard_rho算法 POJ 1811&2429

    素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: h ...

  3. 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 ...

  4. 【poj 2429】GCD & LCM Inverse (Miller-Rabin素数测试和Pollard_Rho_因数分解)

    本题涉及的算法个人无法完全理解,在此提供两个比较好的参考. 原理 (后来又看了一下,其实这篇文章问题还是有的……有时间再搜集一下资料) 代码实现 #include <algorithm> ...

  5. poj 1811 Prime Test 大数素数测试+大数因子分解

    Prime Test Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 27129   Accepted: 6713 Case ...

  6. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  7. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  8. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  9. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

随机推荐

  1. JDK的命令行工具系列 (一) jps、jstat

    概述 在我们进行故障定位和性能分析时, 可以使用Java Dump(也叫Dump文件)来帮助排查问题, 它记录了JVM运行期间的内存占用和线程执行等情况.其中Heap Dump文件是二进制格式, 它保 ...

  2. mysql主从配置详解(图文)

    最近工作不是很忙,把以前整理的mysql数据库的主从配置过程记录一下,有不足之处,请各位多多纠正指教 #环境配置#master IP:192.168.46.137 slave IP:192.168.4 ...

  3. Unity基础之:UnityAPI的学习

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  4. 最基础的 ant build 脚本

    最基础的 ant build 脚本,根据项目,自行进行修改 <?xml version="1.0" encoding="UTF-8" ?> < ...

  5. Java 8 Stream实践

    [**前面的话**]Java中的Stream于1.8版本析出,平时项目中也有用到,今天就系统的来实践一下.下面借用重庆力帆队伍中我个人比较喜欢的球员来操作一波,队员的年龄为了便于展示某些api做了调整 ...

  6. java虚拟机学习笔记(四)---回收方法区

    Java虚拟机规范中规定不要求虚拟机在方法区实现垃圾收集,而且在方法区实现垃圾收集性价比确实很低.在堆中,尤其是新生代,一次垃圾收集可以回收75%-95%的空间,而永久代的垃圾回收效率远低于此. 永久 ...

  7. javaWeb 中前端Form表单数据处理(手动拼json)

    在前端我们会用到最多的就是form表单提交数据,在form表单中有很多都是自动将数据传到后台,然后通过实体来接受的,但是有的时候我们就是需要在前端就拿到这个Form表单的数据,这是我们就可以自己讲数据 ...

  8. (二十八)c#Winform自定义控件-文本框(一)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  9. python语言特点简介 以及在Windows以及Mac中安装以及配置的注意事项

    正如前一篇随笔所提到的,python属于解释型语言 python语言有两个特点: 1.胶水语言(历史遗留问题,原来Perl语言作为Unix内置标准件,获得极大追捧,作为竞争者的python一开始是作为 ...

  10. 访问CGI程序时不添加 /cgi-bin/ 目录也可访问

    配置如下 <VirtualHost *:80> DocumentRoot D:\web_root\test ServerName www.test.com <Directory /& ...