UVa 11440 Help Tomisu
2016-11-04 19:51
225 查看
After wasting a significant time of his life in problem-setting, Mr. Tomisu is now searching for glory: Aglory that will make him famous like Goldbach and rich like Bill Gates :). And he has chosen
the fieldof Number Theory as his prime interest. His creator did not make him very bright and so he needsyour help to solve an elementary problem, using which he will begin his pursuit for glory!Tomisu has come to know that finding out numbers having large
prime factors are very importantin cryptography. Given two integers N and M, he aims to count the number of integers X between 2and N! (factorial N), having the property that all prime factors of X are greater than M.
Input
The input file contains at most 500 lines of inputs. Each line contains two integers N (1 < N <10000001) and M (1 ≤ M ≤ N and N − M ≤ 100000). Input is terminated by a line containing twozeroes. This
line should not be processed.
Output
For each line of input produce one line of output. This line contains the value T %100000007 (Modulo100000007 value of T). Here T is the total number of numbers between 1 and N! (factorial N) whichhave
prime factors greater than M.
Sample Input
100 10
100 20
10000 9000
0 0
Sample Output
43274465
70342844
39714141
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
欧拉函数+神奇的思路~
这里的fi[i]表示的是小于i!的质因子个数,与一般的欧拉函数不同~
(好像欧拉函数应该是phi?)
这道题要求的是1…n!中有多少数与m!互质,也就相当于是求1…n中有多少数与m互质。
然后就能转化为求2..n!中有多少个x满足x的所有质因子都大于m,用欧拉函数可以很方便地求出来~
the fieldof Number Theory as his prime interest. His creator did not make him very bright and so he needsyour help to solve an elementary problem, using which he will begin his pursuit for glory!Tomisu has come to know that finding out numbers having large
prime factors are very importantin cryptography. Given two integers N and M, he aims to count the number of integers X between 2and N! (factorial N), having the property that all prime factors of X are greater than M.
Input
The input file contains at most 500 lines of inputs. Each line contains two integers N (1 < N <10000001) and M (1 ≤ M ≤ N and N − M ≤ 100000). Input is terminated by a line containing twozeroes. This
line should not be processed.
Output
For each line of input produce one line of output. This line contains the value T %100000007 (Modulo100000007 value of T). Here T is the total number of numbers between 1 and N! (factorial N) whichhave
prime factors greater than M.
Sample Input
100 10
100 20
10000 9000
0 0
Sample Output
43274465
70342844
39714141
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
欧拉函数+神奇的思路~
这里的fi[i]表示的是小于i!的质因子个数,与一般的欧拉函数不同~
(好像欧拉函数应该是phi?)
这道题要求的是1…n!中有多少数与m!互质,也就相当于是求1…n中有多少数与m互质。
然后就能转化为求2..n!中有多少个x满足x的所有质因子都大于m,用欧拉函数可以很方便地求出来~
#include<cstdio> #include<iostream> using namespace std; #define inf 10000000 #define modd 100000007 #define ll long long ll n,m,a[inf+1],fi[inf+1]; bool b[inf+1]; void findd() { fi[1]=1;fi[2]=1; for(ll i=2;i<=inf;i++) { if(!b[i]) a[++a[0]]=i; for(ll j=1;a[j]*i<=inf;j++) { b[i*a[j]]=1; if(!(i%a[j])) break; } } for(int i=3;i<=inf;i++) fi[i]=(b[i] ? i*fi[i-1]:(i-1)*fi[i-1])%modd; } int main() { findd(); while(scanf("%lld%lld",&n,&m)==2 && n) { ll ans=fi[m]; for(ll i=m+1;i<=n;i++) ans=ans*i%modd; printf("%lld\n",(ans-1+modd)%modd); } return 0; }
相关文章推荐
- Help Tomisu UVA - 11440 难推导+欧拉函数,给定正整数N和M, 统计2和N!之间有多少个整数x满足,x的所有素因子都大于M (2<=N<=1e7, 1<=M<=N, N-M<=1E5) 输出答案除以1e8+7的余数。
- [UVa 11440]Help Tomisu 数论 欧拉函数+拓欧逆元
- UVA 11440 Help Tomisu 数论+欧拉函数
- UVA 11440 Help Tomisu
- UVa 11440 Help Tomisu (数论欧拉函数)
- 【UVA】11440 - Help Tomisu
- uva11440 Help Tomisu
- UVa 11440 Help Tomisu 欧拉函数
- UVA 11440 Help Tomisu
- uva 11440 Help Mr. Tomisu 欧拉函数变种
- uva11440
- UVA 11440 Help Mr. Tomisu 欧拉phi函数
- 紫书例题 10-26 UVa 11440
- UVa 11440 (欧拉函数) Help Tomisu
- UVA 11440
- UVA 11440(p338)----Help Mr.Tomisu
- UVA 11440 - Help Tomisu(欧拉函数)
- UVa11440 - Help Tomisu(数论)
- uva 11440 - Help Tomisu(欧拉函数)
- uva 11440 - Help Tomisu(欧拉功能)