1694:primorial vs LCM time limit: 4 Sec memory limit: MB
Submitted State [Discussion Version] Title Description given n (2<=n<=10^14), what is the quotient of LCM (,...., N) divided by multiple of all primes upto N. As the result might be too big, output it's modulo by 1000000007.For example, when n=5, the result is LCM (1,2,3,4,5)/(2*3* 5) =60/30=2.note that LCM stands for Lowest or Least Common multiple.
Enter the first line of the input was T (t≤50000), then T-Test cases follows in next T lines. Each linecontains an integer N (2≤n≤100000000000000 or 10^14). The meaning of N is given in theproblem statement.
The output for the test case prints a line in ' Case x:s ' format where x is the case number and S are thequotient modulo by 1000000007.
Sample input
1023456789101000
Sample output
Case 1:1case 2:1case 3:2case 4:2case 5:2case 6:2case 7:4case 8:12case 9:12case 10:744,593,350
Idea: It is obvious that the contribution of less than N of a prime number is less than n for the n-1 of that prime number;
Because the one-time side is useless, so the prime number to hit the table to sqrt (E14);
Find the prefix product, the two-point search position;
Pay attention to super memory with, get contribution there must be double;
#include <bits/stdc++.h>using namespacestd;#definell unsigned long long#defineMoD 1000000007#defineINF 100000000000005#defineMAXN 10000010//#pragma COMMENT (linker, "/stack:102400000,102400000")intScan () {intres =0, ch; while( ! (ch = getchar ()) >='0'&& CH <='9' ) ) { if(ch = = EOF)return 1<< - ; } Res= CH-'0' ; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;} Vector<pair<ll, LL > >V;vector<ll>ans;ll prime[maxn],cnt;BOOLVIS[MAXN];voidPrime () {CNT=0; memset (Vis,0,sizeof(VIS)); V.push_back (Make_pair (1LL,1LL)); for(LL i=2; i<maxn;i++) { if(!Vis[i]) {prime[cnt++]=i; for(DoubleJ= (Double) i*i;j<inf;j*=i) V.push_back (Make_pair (LL) j,i); } for(LL j=0; j<cnt&&i*prime[j]<maxn;j++) {vis[i*prime[j]]=1; if(i%prime[j]==0) Break; }} sort (V.begin (), V.end ()); Ans.push_back (1LL); for(intI=1; I<v.size (); i++) Ans.push_back ((Ans[i-1]*v[i].second)%mod);}intMain () {ll x,y,z,i,t; Prime (); intt,cs=1; scanf ("%d",&T); while(t--) {scanf ("%llu",&x); LL St=0; ll en=v.size ()-1; while(st<en) {ll Mid= (St+en)/2; if(v[mid].first>x) en=mid; ElseSt=mid+1; } if(x>=v[st].first) printf ("Case %d:%llu\n", cs++,ans[st]%MoD); Else if(x>=v[st-1].first) printf ("Case %d:%llu\n", cs++,ans[st-1]%MoD); } return 0;}
View Code
Neu 1694 primorial vs LCM number theory