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