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: ...
随机推荐
- nginx反向代理ajax,解决跨域问题
server { listen 8000; server_name somename alias another.alias; location /a { add_header 'Access-Con ...
- HDU 5695 Gym Class
拓扑排序. #include<cstdio> #include <iostream> #include<cstring> #include<cmath> ...
- java面向对象基础编程题
第一题: 设计一个形状类Shape,方法:求周长和求面积.形状类的子类:Rect(矩形),Circle(圆形).Rect类的子类:Square(正方形).不同的子类会有不同的计算周长和面积的方法1.总 ...
- idea2019设置智能提示忽略大小写
2019的设置和2018的不太一样,话不多说,直接上干货.setting --> Editor --> General --> Code Completion 直接把这个选项前面的勾 ...
- 怎样解读Caffe源代码
怎样解读Caffe源代码 导读 Caffe是如今非常流行的深度学习库,能够提供高效的深度学习训练.该库是用C++编写.能够使用CUDA调用GPU进行加速.可是caffe内置的工具不一定能够满足用户的全 ...
- linux用户列表
centos上面不知道添加了多少个账户,今天想清理一下,但是以前还未查看过linux用户列表, 一般情况下是 cat /etc/passwd 可以查看所有用户的列表 w 可以查看当前活跃的用户列表 c ...
- Linux——系统调用笔记1
底层文件访问: 进程:运行中的程序,它有一些与值关联的文件描述符,有多少个文件描述符取决于系统配置情况. 当一个程序开始运行时,一般会打开三个文件描述符: 0:标准输入 ...
- RabbitMQ常用命令、管理界面
1.运行CMD,cd切换到RabbitMQ安装目录sbin下E:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.2\sbin 执行 rabbitm ...
- R.layout引用不了布局文件
删除import android.R 引用包所在的R文件..
- 分页语句-取出sql表中第31到40的记录(以自动增长ID为主键)
sql server方案1: id from t order by id ) orde by id sql server方案2: id from t order by id) order by id ...