题意:给一个 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;
}

UVa 11440 Help Tomisu (数论欧拉函数)的更多相关文章

  1. UVa 11440 - Help Tomisu(欧拉函数 + 问题转换)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. 数论-欧拉函数-LightOJ - 1370

    我是知道φ(n)=n-1,n为质数  的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...

  3. 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)

    题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...

  4. BZOJ-2190 仪仗队 数论+欧拉函数(线性筛)

    今天zky学长讲数论,上午水,舒爽的不行..后来下午直接while(true){懵逼:}死循全程懵逼....(可怕)Thinking Bear. 2190: [SDOI2008]仪仗队 Time Li ...

  5. UVA 11424 GCD - Extreme (I) (欧拉函数+筛法)

    题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gcd(n-1,n) 此 ...

  6. Codeforces_776E: The Holmes Children (数论 欧拉函数)

    题目链接 先看题目中给的函数f(n)和g(n) 对于f(n),若自然数对(x,y)满足 x+y=n,且gcd(x,y)=1,则这样的数对对数为f(n) 证明f(n)=phi(n) 设有命题 对任意自然 ...

  7. Codeforces 776E: The Holmes Children (数论 欧拉函数)

    题目链接 先看题目中给的函数f(n)和g(n) 对于f(n),若自然数对(x,y)满足 x+y=n,且gcd(x,y)=1,则这样的数对对数为f(n) 证明f(n)=phi(n) 设有命题 对任意自然 ...

  8. 数论 - 欧拉函数模板题 --- poj 2407 : Relatives

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Descri ...

  9. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: ...

随机推荐

  1. msp430项目编程21

    msp430中项目---直流电机控制系统 1.定时器工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习

  2. Thinkphp5学习 Windows下的安装

    方法一.通过官方网站直接下载: (1)下载地址:http://www.thinkphp.cn/down.html: (2)下载后,解压到web目录下: (3)访问:http://localhost/目 ...

  3. Codeforces 659B Qualifying Contest【模拟,读题】

    写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...

  4. loj515 贪心只能过样例(bitset)

    题目: https://loj.ac/problem/515 分析: 所有可能和的最大值是1e6 如果dp的话,dp[i][j]表示前i个数能否凑出和为j的数 这样是O(n^5)的 考虑到[j]可以用 ...

  5. 前后端分离项目shiro的未登录和权限不足

    在前后端分离的项目中.前端代码和后端代码几乎不在同一个目录下,甚至不是在一台服务器上:我这个项目部署在linux.同一台服务器,不同目录下:所有的页面跳转由前台路由,后台只是提供返回的数据: 干货↓  ...

  6. eclipse提速01 - 禁用不常用的eclipse启动插件

    会不断更新,需要的收藏 禁用不常用的eclipse启动插件(当然如果不需要可以卸载)

  7. zz年度热门编程语言排行榜

    原文在这里:Link 蛮有意思的,可以看看.

  8. python菜鸟日记1

    1. 在__init__(self,...)初始化函数中.定义对象的属性,这些属性不用所有写在括号里,括号里的表示定义的时候须要赋初始值的一些属性,而其它不用初始值的属性.能够 直接卸载代码块中,se ...

  9. 【求建议】毕业之声——信院IT类毕业学子经验分享交流会

    一:缘由 在和非常多学子交流,及上课的经历中,发现一个非常普遍的现象:部分大一学生即失去了对学习.对专业的兴趣.有人在迷茫之后奋起直追.从而珍惜利用不多的大学时光努力提高自己.有人在迷茫中沉沦,沉迷于 ...

  10. Android NDK 环境搭建

    使用最新ndk,直接抛弃cygwin,曾经做Android的项目要用到NDK就必需要下载NDK,下载安装Cygwin(模拟Linux环境用的),下载CDT(Eclipse C/C++开发插件),还要配 ...