LCM of 1 to n by mirac

v[999],i,k,t,c;main(M){while(~scanf("%d",&i)){for(;c=i;i--)for(k=1;k++-i;t=0){while(c%k==0)t++,c/=k;if(v[k]<t)v[k]=t;}char b[999]={1},*p,*q,o[999];for(i=999;i;i--)for(bcopy(b,o,999),k=1;k<pow(i,v[i]);k++)for(c=0,t=M,p=&b,q=&o;t>0|c;c=9<(*p+=*q+++c),*p++%=10)if(!t--)M++;while(M)putchar(b[--M]+48);M=puts("");}}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page