UVa 11440 Help Tomisu (数论欧拉函数)
题意:给一个 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 (数论欧拉函数)的更多相关文章
- UVa 11440 - Help Tomisu(欧拉函数 + 问题转换)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 数论-欧拉函数-LightOJ - 1370
我是知道φ(n)=n-1,n为质数 的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- BZOJ-2190 仪仗队 数论+欧拉函数(线性筛)
今天zky学长讲数论,上午水,舒爽的不行..后来下午直接while(true){懵逼:}死循全程懵逼....(可怕)Thinking Bear. 2190: [SDOI2008]仪仗队 Time Li ...
- 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) 此 ...
- 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) 设有命题 对任意自然 ...
- 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) 设有命题 对任意自然 ...
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 Descri ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
随机推荐
- [NOIP2001] 提高组 洛谷P1025 数的划分
题目描述 将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序). 例如:n=7,k=3,下面三种分法被认为是相同的. 1,1,5; 1,5,1; 5,1,1; 问有多少种不同的分法. 输 ...
- csu 1600: Twenty-four point
传送门 1600: Twenty-four point Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 490 Solved: 78[Submit][S ...
- Python中排序的灵活使用
Python中列表按指定标准排序实例 概述 本题需要先输入机器的数目和任务的数目. 在接下来的n行中每行分别包含机器的最大执行时间和机器所能执行任务的最大强度. 在接下来的n行中每行分别包含任务执行时 ...
- UVA 861 组合数学 递推
题目链接 https://vjudge.net/problem/UVA-861 题意: 一个国际象棋棋盘,‘象’会攻击自己所在位置对角线上的棋子.问n*n的棋盘 摆放k个互相不攻击的 '象' 有多少种 ...
- Dividing--hdu1059(动态规划)
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- java内存区域和对象的产生
一直被java中内存组成弄的头晕眼花,这里总结下都有哪些,先上图片 程序计数器 小块内存,线程执行字节码的信号指示器,以此获取下一条需要执行的字节码指令,分支,循环,跳转,异常处理,线程恢复都要依赖他 ...
- 了解kaggle
Kaggle官网 数据挖掘的比赛,主要是特征工程 Kaggle 数据挖掘比赛经验分享 Kaggle 机器学习竞赛冠军及优胜者的源代码汇总 程序化广告交易中的点击率预估
- Oracle 数据库管理员的任务
设计.实施和维护 Oracle 数据库时,按优先次序排列的任务包括: 1. 确定数据库服务器硬件 2. 安装 Oracle 软件 3. 为数据库和安全策略制定计划 4. 创建.移植和打 ...
- 工作总结 使用html模板发邮件 前面空一大块
HTML邮件的本质其实是发送了一个html页面.邮件的空白必然是页面的空白,所以你要找到你发送邮件的html模板所在,然后去掉空白即可,如果这是一个公共文件,需要注意你往往用的只是你的部分,很大程度还 ...
- NS3网络仿真(12): ICMPv4协议
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 ICMP的全称是 Internet ControlMessage Protocol . 其目的就是 ...