input

样例个数T           <=10000

每个样例一个n(2<=n<=10^8)

output

lcm(1,2,...,n)%2^32

Sample Input

5
10
5
200
15
20

Sample Output

2520
60
2300527488
360360
232792560 做法:质因分解,每个不大于n的质数不大于n的最高次幂相乘结果即为lcm(1,2,...,n)的结果
 #include <bits/stdc++.h>
#define MAX 10000
#define INF 100000000
#define LL long long
#define U unsigned
using namespace std;
int cas=,T;
U int prime[],pn,*r,rn,*rr,n,*rrp;
struct node
{
U int x,y;
bool operator<(const node&a)const
{
return x>a.x;
}
};
/*void init() //TLE
{
pn=1;
bool *vis=new bool[INF+10];
priority_queue<node>q;
for(int i=2;i<=MAX;i++)
if(!vis[i])
{
for(int j=i*i;j<=INF;j+=i) vis[j]=1;
q.push(node{i,i});
}
prime[0]=1;
for(U int i=MAX+1,x=1;i<=INF;i++)
{
if(!vis[i]) prime[pn++]=i;
}
prime[pn++]=INF+10;
delete []vis;
r=new U int[pn+10];
r[0]=1;
for(int i=1;i<pn;i++) r[i]=r[i-1]*prime[i];
U int res=1;
rr=new U int[3000];
rrp=new U int[3000];
rr[0]=rrp[0]=1;
rn=1;
while(!q.empty())
{
node u=q.top();q.pop();
rrp[rn]=u.x;
rr[rn++]=res*u.y;
if((U LL)u.x*u.y<=INF) q.push(node{u.x*u.y,u.y});
}
rrp[rn++]=INF+10;
for(int i=1;i<rn;i++) rr[i]=rr[i-1]*rr[i];
}
*/
void init() //最大数为10000^2,则大于10000的素数最小公倍数的最大次幂为1,小于一万时不定
{
bool *vis=new bool[INF+];
pn=;
for(U int i=;i<=INF;i++) //O(n)筛法
{
if(!vis[i]) prime[pn++]=i;
for(U int j=;j<pn&&i*prime[j]<=INF;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
delete []vis; //内存不足,用完即删
priority_queue<node>q;
r=new U int[pn];
for(int i=;i<pn;i++) //prime存质数,r存第i个质数对应的结果(还没算1~10000的部分)
{
if(prime[i]<=MAX) { r[i]=;q.push(node{prime[i],prime[i]}); }
else r[i]=r[i-]*prime[i];
}
U int res=;
rr=new U int[];
rrp=new U int[];
rr[]=rrp[]=;
rn=;
while(!q.empty()) //rr存质数的幂次升序,rrp存底数
{
node u=q.top();q.pop();
rrp[rn]=u.x;
rr[rn++]=res*u.y;
if((U LL)u.x*u.y<=INF) q.push(node{u.x*u.y,u.y});
}
rrp[rn++]=INF+;
for(int i=;i<rn;i++) rr[i]=rr[i-]*rr[i]; //将rrp乘起来作为1~10000的结果
}
int main()
{
//printf("%d\n",sizeof(vis)+sizeof(prime));
init();
// for(int i=0;i<rn;i++) printf("%u %u\n",rrp[i],rr[i]);
//freopen("1.in","w",stdout);
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
scanf("%d",&T);
while(T--)
{
scanf("%u",&n);
int i1=upper_bound(prime,prime+pn,n)--prime; //查找>10000的结果
int i2=upper_bound(rrp,rrp+rn,n)--rrp; //查找1~10000的结果
printf("%u\n",r[i1] * rr[i2]);
}
delete []r;
delete []rrp;
delete []rr;
return ;
}

ACdream 1732的更多相关文章

  1. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  2. 矩阵乘法快速幂 codevs 1732 Fibonacci数列 2

    1732 Fibonacci数列 2  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 在“ ...

  3. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  4. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  5. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  6. acdream.Bet(数学推导)

    Bet Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Status Pra ...

  7. acdream.郭式树(数学推导)

    郭式树 Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Pr ...

  8. ACdream 1188 Read Phone Number (字符串大模拟)

    Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Sub ...

  9. ACdream 1195 Sudoku Checker (数独)

    Sudoku Checker Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. 异步队列 Deferred

    异步队列 Deferred 背景: 移动web app开发,异步代码是时常的事,比如有常见的异步操作: Ajax(XMLHttpRequest) Image Tag,Script Tag,iframe ...

  2. activity的android:name所指的Activity实现类的简写问题

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package=" ...

  3. 使用mysqldump 对数据库进行备份的乱码问题

    最近在做项目的工程中,由于系统中需要提供数据库备份的功能,经过网上一番搜索,觉得采用简单的mysqldump (1)java代码 String backupSQL = "cmd /c mys ...

  4. [ios2] iOS常用控件尺寸大集合 【转】

    元素控件 尺寸(PTS) Window(含状态栏) 320 x 480 Status Bar的高度 20 Navigation Bar的高度 44 含Prompt的Navigation Bar的高度 ...

  5. 【Java每日一题】20170112

    20170111问题解析请点击今日问题下方的"[Java每日一题]20170112"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  6. (转载)python日期函数

    转载于http://www.cnblogs.com/emanlee/p/4399147.html 所有日期.时间的api都在datetime模块内. 1. 日期输出格式化 datetime => ...

  7. POJ3177 Redundant Paths 双连通分量

    Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...

  8. CA认证

    nginx下证书配置 nginx 下 配 置 CA 认 证   为nginx配置https并自签名证书   开启443端口   实验环境: centos6.5    192.168.16.14   [ ...

  9. 纯CSS实现tab选项卡切换

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta cont ...

  10. Ajax beforeSend和complete 方法与防止重复提交

    $.ajax({ beforeSend: function(){ // Handle the beforeSend event }, complete: function(){ // Handle t ...