UVA 11440 Help Mr. Tomisu 欧拉phi函数
2015-02-03 14:18
330 查看
欧拉phi函数的改进版.....
/* ***********************************************
Author :CKboss
Created Time :2015年02月02日 星期一 16时13分33秒
File Name :UVA11440.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
const LL mod = 100000007LL ;
const int maxn = 10001000;
LL n,m;
bool vis[maxn];
LL phiac[maxn];
/// get prime
void getPRIME()
{
memset(vis,true,sizeof(vis));
vis[0]=vis[1]=false;
for(int i=2;i*i<maxn;i++)
{
if(vis[i]==false) continue;
for(int j=2*i;j<maxn;j+=i)
vis[j]=false;
}
}
void init()
{
getPRIME();
/// phiac
=phi[n!]
phiac[1]=phiac[2]=1;
for(int i=3;i<maxn;i++)
{
if(vis[i]==false) phiac[i]=(phiac[i-1]*i)%mod;
else phiac[i]=(phiac[i-1]*(i-1))%mod;
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
init();
while(cin>>n>>m)
{
if(n==0&&m==0) break;
LL temp = phiac[m];
for(int i=m+1;i<=n;i++)
temp =( temp * i )%mod;
cout<<(temp-1+mod)%mod<<endl;
}
return 0;
}
Help Tomisu
Description Problem D Help Mr. Tomisu Input: Standard Input Output: Standard Output After wasting a significant time of his life in problem-setting, Mr. Tomisu is now searching for glory: A glory that will make him famous like Goldbach and rich like Bill Gates :). And he has chosen the field of Number Theory as his prime interest. His creator did not make him very bright and so he needs your 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 important in cryptography. Given two integers N and M, he aims to count the number of integers x between 2 and 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 two zeroes. This line should not be processed. OutputFor each line of input produce one line of output. This line contains the value T % 100000007 (Modulo 100000007 value of T). Here T is the total number of numbers between 1 and N! (factorial N) which have prime factors greater than M.Sample Input Output for Sample Input
Special Thanks: Per Austrin Source Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples Root :: Prominent Problemsetters :: Shahriar Manzoor Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Number Theory :: Exercises: Intermediate Submit Status |
Author :CKboss
Created Time :2015年02月02日 星期一 16时13分33秒
File Name :UVA11440.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
const LL mod = 100000007LL ;
const int maxn = 10001000;
LL n,m;
bool vis[maxn];
LL phiac[maxn];
/// get prime
void getPRIME()
{
memset(vis,true,sizeof(vis));
vis[0]=vis[1]=false;
for(int i=2;i*i<maxn;i++)
{
if(vis[i]==false) continue;
for(int j=2*i;j<maxn;j+=i)
vis[j]=false;
}
}
void init()
{
getPRIME();
/// phiac
=phi[n!]
phiac[1]=phiac[2]=1;
for(int i=3;i<maxn;i++)
{
if(vis[i]==false) phiac[i]=(phiac[i-1]*i)%mod;
else phiac[i]=(phiac[i-1]*(i-1))%mod;
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
init();
while(cin>>n>>m)
{
if(n==0&&m==0) break;
LL temp = phiac[m];
for(int i=m+1;i<=n;i++)
temp =( temp * i )%mod;
cout<<(temp-1+mod)%mod<<endl;
}
return 0;
}
相关文章推荐
- uva 11440 Help Mr. Tomisu 欧拉函数变种
- UVA 11440(p338)----Help Mr.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 10820 - Send a Table(欧拉phi函数的应用)
- uva11440
- UVA 11440 Help Tomisu
- UVA10214 Trees in a Wood. 欧拉phi函数
- 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 数论 欧拉函数+拓欧逆元
- 紫书例题 10-26 UVa 11440
- UVA 11440 Help Tomisu
- UVa 11440 Help Tomisu
- UVA 11440
- UVA11440HelpMr.Tomisu