您的位置:首页 > 其它

UVa 11440 Help Tomisu (数论欧拉函数)

2016-11-09 20:01 344 查看
题意:给一个 n,m,统计 2 和 n!之间有多少个整数x,使得x的所有素因子都大于M。

析:首先我们能知道的是 所有素数因子都大于 m 造价于 和m!互质,然后能得到 gcd(k mod m!, m!) = 1,也就是只要能求出不超过 m!且和 m!

互质的个数就好,也就是欧拉函数呗,但是,,,m!也非常大,根本无法用筛选法进行,但是可以通过递推进行,根据欧拉公式,能知道n! 和 (n-1)!

如果n为中素数,那么它们的素因子肯定是一样的,如果n是素数,那么就会多一项,所以我们能够得到递推式。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <ctime>
#include <cstdlib>
#define debug puts("+++++")
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1;

typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e7 + 5;
const LL mod = 100000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){  return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){  return b == 0 ? a : gcd(b, a%b); }
inline int lcm(int a, int b){  return a * b / gcd(a, b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
bool vis[maxn];
LL dp[maxn];

int main(){
m = sqrt(maxn-0.5);
for(int i = 2; i <= m; ++i)  if(!vis[i])
for(int j = i*i; j < maxn; j += i)  vis[j] = true;
dp[1] = dp[2] = 1LL;
for(int i = 3; i < maxn; ++i)
dp[i] = dp[i-1] * (vis[i] ? i : i-1) % mod;
while(scanf("%d %d", &n, &m) == 2 && m+n){
LL ans = dp[m];
for(int i = m+1; i <= n; ++i)  ans = ans * i % mod;
cout << (ans - 1 + mod) % mod << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: