neu 1694 Primorial vs LCM 数论

1694: Primorial vs LCM

时间限制: 4 Sec  内存限制: 128 MB
[提交][状态][讨论版]

题目描述

Given N (2<=N<=10^14), what is the quotient of LCM(1,2,3,....,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 LCM stands for Lowest or Least Common Multiple.

输入

The first line of the input is 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.

输出

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.

样例输入

10
2
3
4
5
6
7
8
9
10
1000

样例输出

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: 744593350思路:显然是求小于一个素数的n次方小于N的贡献为那个素数的n-1次方;   因为一次方是没用的,所以素数打表到sqrt(e14);   求出前缀积,二分查找位置;   注意超内存跟,得到贡献那里必须要double;

#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define mod 1000000007
#define inf 100000000000005
#define MAXN 10000010
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
    int res = 0 , ch ;
    while( !( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ ) )
    {
        if( ch == EOF ) return 1 << 30 ;
    }
    res = ch - ‘0‘ ;
    while( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ )
        res = res * 10 + ( ch - ‘0‘ ) ;
    return res ;
}
vector<pair<ll ,ll > >v;
vector <ll>ans;
ll prime[MAXN],cnt;
bool vis[MAXN];
void Prime()
{
    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(double j=(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(int i=1;i<v.size();i++)
    ans.push_back((ans[i-1]*v[i].second)%mod);
}
int main()
{
    ll x,y,z,i,t;
    Prime();
    int T,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;
            else
            st=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;
}

 
时间: 2024-10-19 12:03:05

neu 1694 Primorial vs LCM 数论的相关文章

1694: Primorial vs LCM 数论

链接:戳这里 1694: Primorial vs LCM 时间限制: 4 Sec  内存限制: 128 MB [提交][状态][讨论版] 题目描述 Given N (2<=N<=10^14), what is the quotient of LCM(1,2,3,....,N) divided by multiple of all primes up to N. As the result might be too big, output it's modulo by 1000000007.

HDU4497 GCD and LCM 数论 素数分解

题意很简单首先以前做最简单的LCM跟CGD的时候都知道先求出两个数A,B的最大公约数GCD,那么LCM可以利用  A*B/GCD来求得,这点一开始脑残了没想到,结果没有进行特盘所以错了,意思就是 题目给的L%G不为0的话就是无解,结果我给判其它的去了,肯定漏了些什么没有发现 然后对于 L/G进行素因子分解,同时任意的数都能够通过素因子分解来表示,所以三个解x,y,z也能分解 L/G = p1^q1*p2^q2.... x = p1^i1*... y = p1^j1*... z = p1^k1*.

NEU1694: Primorial vs LCM

链接:http://acm.neu.edu.cn/hustoj/problem.php?id=1694 题意:给定多个n,求LCM(1~n)/pi{pi为1~n中的素数}. 分析:因为n太大有10^14,我们得观察一些性质才行.因为要求的是最小公倍数然后除掉所有的质数,这里很明显大于sqrt(n)的素数就没意义了,因为最后答案中留下的只能是指数大于1的素数.那么我们就将素数范围缩小到了10^7,然后我们再来看看有什么其他的性质,我们会知道素数p在答案中的贡献应该是p^k<=n<p^(k+1)时

Uva 11388 GCD LCM ( 数论 )

Uva  11388 GCD LCM( 数论 ) 题意: 求是否存在a,b 使得lcm(a,b) = L, gcd(a,b) = G,不存在输出-1,存在输出a,b,且a尽可能小 分析: 强行暴力是不可能的数据很大,要用llu,这里有两种思路 思路一: 由题意可知 a*b = G*L 保证a = G的倍数的情况下,枚举a再判断G*L能否整除a,最后判断b是否为a的倍数.a从G开始扫到sqrt(G*L) //输入两个整数G,L //找出a,b 使得 gcd(a,b) = G lcm(a,b) =

hdu 4497 GCD and LCM 数论 素数分解

GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1339    Accepted Submission(s): 607 Problem Description Given two positive integers G and L, could you tell me how many solutions of

UVA 10791 Minimum Sum LCM 数论

题目链接: https://vjudge.net/problem/UVA-10791 题目描述: 给一个数n, 让你求至少两个数的lcm是n 的, 最小和 解题思路: 唯一分解, 每个单独的素数的幂加起来就是答案 代码: #include <iostream> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iterator

LightOJ 1215 Finding LCM(数论)

题意  已知LCM(a, b, c) = L 和 a.b.L   求最小的满足等式的c. 把数展开为素因子积的形式后 GCD(a,b)就是a,b的公共素因子取在a.b中的较小指数 LCM(a,b)就是a,b的所有素因子取在a.b中的较大指数 令m = LCM(a,b)  那么问题转化为了求最小的c满足 LCM(m, c) = L 那么最小的c就是L中不在m中的素因子和L中指数大于m中指数的素因子取在L中的指数即积 #include <bits/stdc++.h> using namespace

UVA 10791 Minimum Sum LCM (数论)

LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is a multiple of all integers of that set. It is interesting to note that any positive integer can be expressed as the LCM of a set of positive integers. For exa

数论入门2——gcd,lcm,exGCD,欧拉定理,乘法逆元,(ex)CRT,(ex)BSGS,(ex)Lucas,原根,Miller-Rabin,Pollard-Rho

数论入门2 另一种类型的数论... GCD,LCM 定义\(gcd(a,b)\)为a和b的最大公约数,\(lcm(a,b)\)为a和b的最小公倍数,则有: 将a和b分解质因数为\(a=p1^{a1}p2^{a2}p3^{a3}...pn^{an},b=p1^{b1}p2^{b2}p3^{b3}...pn^{bn}\),那么\(gcd(a,b)=\prod_{i=1}^{n}pi^{min(ai,bi)},lcm(a,b)=\prod_{i=1}^{n}pi^{max(ai,bi)}\)(0和任何