UVa 11440 (Euler function) help Tomisu

Source: Internet
Author: User

Test instructions

Given N and M, statistical interval x∈[2, n!],x satisfies the number of x that all element factors are greater than M.

Analysis:

First, the problem is transformed, all the element factor is greater than m equivalent to the number and m!

For k greater than m!,k and m! reciprocity is equivalent to K% M! and m!

So we can find φ (m!) (Φ is Euler's function) and multiplied by n! /m!, last answer minus one (because it was counted from 2)

The formula for Euler's function is a

Phifac[n] =φ (n!), we pass the derivation PHIFAC

When n is composite, n! and (n-1) are the same set of factors, so phifac[n] = n * phifac[n-1]

When n is a prime number, n! has a factor n, and one More (1-1/n) in the formula, so phifac[n] = n * (n-1)/n * phifac[n-1] = (n-1) * Phifac[n-1]

1#include <cstdio>2#include <cmath>3 4 Const intMAXN =10000000+Ten;5 Const intMOD =100000007;6 intPHIFAC[MAXN];7 BOOLVIS[MAXN];8 9 voidSieveintN)Ten { One     intm = sqrt (n +0.5); A      for(inti =2; I <= m; ++i)if(!Vis[i]) -          for(intj = i*i; J <= N; J + =i) -VIS[J] =true; the } -  - intMain () - { +Sieve10000000); -phifac[1] = phifac[2] =1; +      for(inti =3; I <=10000000; ++i) APhifac[i] = (Long Long) phifac[i-1] * (Vis[i]? i:i-1) %MOD; at  -     intN, M; -      while(SCANF ("%d%d", &n, &m) = =2) -     { -         if(n = =0&& m = =0) Break; -         intAns =Phifac[m]; in          for(inti = m+1; I <= N; ++i) ans = (Long Long) ans * I%MOD; -printf"%d\n", (ans-1+MOD)%MOD); to     } +  -     return 0; the}
code June

UVa 11440 (Euler function) help Tomisu

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.