A - LCM from 1 to n ----Light 1289

Given an integer n, you have to find

lcm(1, 2, 3, ..., n)

lcm means least common multiple. For example lcm(2, 5, 4) = 20, lcm(3, 9) = 9, lcm(6, 8, 12) = 24.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing an integer n (2 ≤ n ≤ 108).

Output

For each case, print the case number and lcm(1, 2, 3, ..., n). As the result can be very big, print the result modulo 232.

Sample Input

5

10

5

200

15

20

Sample Output

Case 1: 2520

Case 2: 60

Case 3: 2300527488

Case 4: 360360

Case 5: 232792560

Sponsor

 

 题意:给一个数n,求1~n 这n个数的最小公倍数。

例:n=10,求 LCM(1,2,3,4,5,6,7,8,9,10)。

针对于这10 个数进行分解有如下结果:

                   1          2          3          4          5          6          7         8         9          10

分解后:     1          2          3        2*2        5          2*3       7     2*2*2     3*3       2*5

可以看出  对于(2,4,8)这三个 数,只需要8就可以了。对于(3,9),只需要9 就可以了, 对于(5,10),只需要10就可以了,

那就剩下6和7了。对于6,那么找到(8,9)的最小公倍数就一定是6的倍数,所以6可以不考虑。那么就剩下(7)了。 综上,只要找到LCM(8,9,5,7)就完成了。四个数中不存在最大公约数,所以LCM(8,9,5,7)=8*9*5*7;即 pow(2,3)*pow(3,2)*5*7。由此可以得出要求1~n的最小公倍数【只需要求出n之前的素数的最高次幂小于n的乘积就可以了】。

想要求1e8内的素数用素数筛 进行打表时,book 数组就不可以使用了。这里使用了一个 函数bitset.【头文件 bitset】;

bitset<2>表示 二进制的长度为2。 初始化每位上为0。

#include
#include
#include
#include
#include
using namespace std;
const int  N=1e8+10;
bitsetbook;
unsigned int sum[5800000];
int su[5800000];
int r=0;
void prime()
{
    for(int i=2; i

 

你可能感兴趣的:(数论)