UVa 10780 Again Prime? No Time.(数论&素因子分解)

10780 - Again Prime? No Time.

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=17 21

The problem statement is very easy. Given a number n you have to determine the largest power of m, not necessarily prime, that divides n!.

Input

The input file consists of several test cases. The first line in the file is the number of cases to handle. The following lines are the cases each of which contains two integers m (1<m<5000) and n (0<n<10000). The integers are separated by an space. There will be no invalid cases given and there are not more that 500 test cases.

Output

For each case in the input, print the case number and result in separate lines. The result is either an integer if m divides n! or a line "Impossible to divide" (without the quotes). Check the sample input and output format.

Sample Input

2

2 10

2 100

Sample Output

Case 1:

8

Case 2:

97

时间: 2024-08-26 16:24:48

UVa 10780 Again Prime? No Time.(数论&amp;素因子分解)的相关文章

UVa 160 Factors and Factorials:数论

160 - Factors and Factorials Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=96 题目点这:http://uva.onlinejudge.org/external/1/160.pdf 思路:遍历1~n计算质因子个数即可. 你若还想再快点的话,就用[n/p]+[n

UVa 10791 Minimum Sum LCM (数论&amp;amp;素因子分解)

10791 - Minimum Sum LCM Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=17 32 LCM (Least Common Multiple) of a set of integers is defined as the minimum

UVa 568 Just the Facts:数论&amp;amp;打表&amp;amp;不打表

568 - Just the Facts Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=509 The expression N!, read as ``N factorial," denotes the product of the first

UVa 694 The Collatz Sequence:数论

694 - The Collatz Sequence Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=635 An algorithm given by Lothar Collatz produces sequences of integers, and is

UVa 10929 You can say 11 (数论)

10929 - You can say 11 Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1870 Introduction to the problem Your job is, given a positive number N, determine

UVa 10892 LCM Cardinality (数论&amp;amp;素因子分解)

10892 - LCM Cardinality Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=18 33 A pair of numbers has a unique LCM but a single number can be the LCM of m

数论之 素因子分解,素数筛选法,欧拉函数和扩展欧几里得算法 (整理)

今天突然想复习一下数论,也就顺便整理了一下关于数论的基础知识, 以后用的时候直接用就行了,也不用现敲了,其实就是有点懒.... 具体解释都在代码里有解释 直接上代码了: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue>

UVa 524 Prime Ring Problem:数论&amp;amp;DFS

524 - Prime Ring Problem Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=465 A ring is composed of n (even number) circles as shown in diagram. Put natural numbers into e

UVa 136 Ugly Numbers (数论)

136 - Ugly Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=72 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2,