Uva11440-help tomisu (number theory)

Source: Internet
Author: User

Test instructions: Given N and M, ask [2,n!] , the number of all quality factors is greater than the number of M

Ideas: ? ( m ! < /span> is less than m! and with the number of m! coprime, and the number of m! coprime, his quality factor certainly does not contain 1-m, so is to meet the conditions. Then for this problem, it is required n!, not with the number of m! coprime, answer modulo 100000007

So first look at a proof:
To find the number of coprime and N in kn, the answer is k? (n) 。
? ( n < /span> Represents the number of 1-n and N coprime, then consider [n + 1, 2n], [2n + 1, 3n] ... Each of the numbers in each interval is equal to 1-n in the number plus kn, for the original and n is not coprime number, plus n will still have a qualitative factor repetition, so still not, then for the original coprime number X,GCD (x, N) = 1, then the GCD (x + kn, n) = 1, is still coprime, So every n interval is the same as the number of n coprime, so the answer k? (n)

So for this question, the answer becomes n! / m ! ? (m! ) ), then the question remains how to ask? (m! ) )。

Known? (n) To find the lawN?(1?1/ p 1 )?(1?1/ p 2 )....(1?1/ p n )(P is the mass factor of N), so m! , the molecule is m! , the denominator is the 1-m of all prime numbers. ( 1 1 / p multiply product

The answer here is to ask, m! Eliminate, getN!/∏(1?1/ p i )mod 1000000007, first preprocessing those tables, each time to calculate can


#include <cstdio> #include <cstring>const long long N = 10000005;const long Long mod = 100000007;long long ispri[ N],fac[n],phi[n];long long EXGCD (Long long A,long long B,long long &x,long long &y) {    if (!b) {X=1;y=0;return A ; A    long long d=exgcd (b,a%b,y,x);    Y-= a/b*x;    return D;} Long Long A,long (long long) {Long long n    x, y;    EXGCD (a,n,x,y);    Return (X+n)%n;} void Get_table () {    fac[0]=fac[1]=1; phi[0]=phi[1]=1;    For (long long i=2;i<n;i++) {        fac[i]= (fac[i-1]*i)%mod;        if (Ispri[i]) {            phi[i]=phi[i-1];            Continue;        }        phi[i]=phi[i-1]* (i-1)%MOD*INV (i,mod)%mod;        For (long long j=i*i;j<n;j+=i)            ispri[j]=1;}    } int N,m;int Main () {    get_table ();    while (~SCANF ("%d%d", &n,&m) &&n) {        printf ("%lld\n", ((fac[n]*phi[m]-1)%mod+mod)%mod);    }    return 0;}
Recently brush problems feel good, light attention to the problem of the feeling is particularly busy, summary has not written. The recent courses have also fallen a lot ... Brush up the problem first!

Uva11440-help tomisu (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.