1694:primorial vs LCM number theory

Source: Internet
Author: User




Link: poke here




1694:primorial vs LCM time limit: 4 Sec Memory limit: mb[submission [status] [discussion] Title description
Given N (2<=n<=10^14), what's the quotient of LCM (,...., N) divided by multiple of all primes up
To 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 the LCM stands for Lowest or Least Common multiple.
Input
The first line of the input was T (t≤50000), then T-Test cases follows in next T lines. Each line
Contains an integer N (2≤n≤100000000000000 or 10^14). The meaning of N is given in the
Problem statement.
Output
For each test case, print a line in ' Case x:s ' format where x is case number and S is the
Quotient modulo by 1000000007.
Sample input
10
2
3
4
5
6
7
8
9
10
1000
Sample output
Case 1:1
Case 2:1
Case 3:2
Case 4:2
Case 5:2
Case 6:2
Case 7:4
Case 8:12
Case 9:12
Case 10:744,593,350


Test Instructions: Find out LCM (1~n)/(prime number product within years)


Ideas: The product of the highest power of the energy of each prime number within the LCM (1~n) = n

LCM (1,2,3,4,,, 49) = 2^5 * 3^3 * 5^2 * 7^2 * 11 *13 ...

Find LCM (1~49) except for 49 primes = 2^4 * 3^3 * 5 * 7

This only needs to calculate the prime number within 1E7 and then take the highest of each prime power-1, you can find out the situation of n=1e14 but still will be T

Since the answer to a continuous n is the same for all to simulate the process (the conclusion here is that the value of the LCM is not changed when a new prime number of the highest power is present)

2 1

3 1

4 2

8 4

9 12

16 24

25 120

Prime^num anw[on a]*prime

below to analyze and analyze

Think about what this is about, because each time a new prime is given the highest power to change the LCM.

So every time the answer is updated, it's here at Prime^num.

And then in the linear sieve there is a record value and then two points output the answer


Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < string> #include <vector> #include <ctime> #include <queue> #include <set> #include <map > #include <stack> #include <iomanip> #include <cmath> #define MST (SS,B) memset ((ss), (b), sizeof (SS )) #define MAXN 0x3f3f3f3f#define MAX 10000005///#pragma comment (linker, "/stack:102400000,102400000") typedef long LONG Ll;typedef unsigned long long ull;using namespace Std;const ll inf=1e14+5; #define MOD 1000000007int t,cas;vector< pair&    lt;ll,int> > V;vector<ll> anw;int vis[max],prime[max];void init () {int cnt=0;    V.push_back (Make_pair (1ll,1));            for (int i=2;i<=max;i++) {if (!vis[i]) {prime[cnt++]=i;            for (double j= (double) i*i;j<inf;j*=i) {V.push_back (Make_pair (LL) j,i);            }} for (int j=0;j<cnt;j++) {if ((ll) i*prime[j]>max) break; vis[i*prime[j]]=1;        if (i%prime[j]==0) break;    }} sort (V.begin (), V.end ());    Anw.push_back (1LL);    for (int i=1;i<v.size (); i++) {anw.push_back (LL) v[i].second*anw[i-1]%mod);    }}ll N;int Main () {init ();    scanf ("%d", &t);        for (int cas=1;cas<=t;cas++) {scanf ("%lld", &n);        int l=0,r=v.size () -1,mid,ans=0;            while (L<r) {mid= (l+r+1)/2;                if (v[mid].first<=n) {l=mid;            Ans=mid;        } else r=mid-1;    } printf ("Case%d:%lld\n", cas,anw[r]%mod); } return 0;}


1694:primorial vs LCM number theory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.