zoj 1850 Factovisors
2011-02-08 18:15
113 查看
Factovisors
Time Limit: 1 Second Memory Limit: 32768 KB
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: University of Waterloo Local Contest 1999.01.31
求m是否能整除n! 其实原理也很简单 首先将所有的质数(16位里面的正整数)筛选出来,推荐用素数筛选法 接着就是质数分解,将m的质数分解,并且得到质数表和质数的个数 接着按照得到的质数表,对n!的阶乘进行寻找相应质数的个数,看是否多余m中的质数的个数,以此判断即可 代码不贴了,比较丑陋
相关文章推荐
- POJ2649 ZOJ1850 UVA10139 Factovisors【筛选法+勒让德定理】
- ZOJ 1060 (POJ 1094) Sorting It …
- ZOJ-1842
- ZOJ 3469 Food Delivery
- ZOJ 3988 && 2017CCPC秦皇岛 H:Prime Set(二分匹配)
- poj 1014 || zoj 1149 Dividing
- zoj--1067--Color Me Less
- ZOJ 2326 Tangled in Cables(最小生成树--prime)
- ZOJ - 3981 A.Balloon Robot 思维
- 【HDU 1005 && ZOJ 3539】简单矩阵dp
- zoj 1216
- ZOJ3556 How Many Sets I(容斥)
- One Person Game ZOJ - 3329 期望dp
- zoj 1438 Asteroids!
- ZOJ 3791 An Easy Game(DP)
- HDU_1850 Being a Good Boy in Spring Festival(Nim)
- ZOJ - 3985 String of CCPC (2017CCPC秦皇岛站 简单题)
- ZOJ 1586 QS Network
- zoj 2587 Unique Attack 网络流
- zoj 3765 块状链表 OR splay