求逆欧拉函数(arc)
已知欧拉函数计算公式
初始公式:φ(n)=n*(1-1/p1)*(1-1/p2).....*(1-1/pm)
又 n=p1^a1*p2^a2*...*ps^as 欧拉函数是积性函数
那么:φ(n)=φ(p1^a1)* φ(p2^a2)........φ(pn^an).
#include<cstdio>
#include<ctime>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#define LL long long
#define maxn 100010
#define MAXN 10000000
using namespace std;
LL n,k,prime[MAXN/],cnt,ans[maxn];
bool mark[MAXN+];
void first()
{
for(int i=;i<=MAXN;i++)
{
if(!mark[i]) prime[++cnt]=i;
for(int j=;j<=cnt;j++)
{
if(i*prime[j]>MAXN) break;
mark[i*prime[j]]=;
if(i%prime[j] ==) break;
}
}
return ;
}
LL mul(LL a,LL b,LL mod)
{
LL ans=;
while(b)
{
if(b&) ans=(ans+a)%mod;
a=(a<<)%mod;b>>=;
}
return ans;
}
LL low(LL a,LL b,LL mod)
{
LL ans=;
while(b)
{
if(b&) ans=mul(ans,a,mod);
b>>=,a=mul(a,a,mod);
}
return ans;
}
bool Is_prime(LL n)
{
if(n<) return ;
if(n==) return ;
if(n% ==) return ;
LL m=n-,j=;
while(m% == )
{
j++;
m>>=;
}
for(int i=;i<=;i++)
{
LL a=rand()%(n-)+;
LL x=low(a,m,n);
LL y;
for(int k=;k<=j;k++)
{
y=mul(x,x,n);
if(y==&&x!=&&x!=n- )
return ;
x=y;
}
if(x!=) return ;
}
return ;
}
void dfs(LL x,LL y,LL mod )
{
if(x==)
{
ans[++ans[]]=y;
return ;
}
if(x+ > prime[cnt] && Is_prime(x+))
ans[++ans[]]=y*(x+);
for(int i=mod;i>=;i--)
if(x%(prime[i]-) == )
{
LL a=x/(prime[i]-),b=y,c=;
while(a%c ==)
{
b*=prime[i];
dfs(a/c,b,i-);
c*=prime[i];
}
}
}
int main()
{
freopen("arc.in","r",stdin);
freopen("arc.out","w",stdout);
scanf("%lld%lld",&n,&k);
srand(time());
first();
dfs(n,,cnt);
sort(ans+,ans++ans[]);
for(int i=;i<=k;i++)
printf("%lld ",ans[i]);
return ;
}
求逆欧拉函数(arc)的更多相关文章
- √n求单值欧拉函数
基本定理: 首先看一下核心代码: 核心代码 原理解析: 当初我看不懂这段代码,主要有这么几个问题: 1.定理里面不是一开始写了一个n*xxx么?为什么代码里没有*n? 2.ans不是*(prime[i ...
- 【BZOJ4803】逆欧拉函数
[BZOJ4803]逆欧拉函数 题面 bzoj 题解 题目是给定你\(\varphi(n)\)要求前\(k\)小的\(n\). 设\(n=\prod_{i=1}^k{p_i}^{c_i}\) 则\(\ ...
- O(n)求素数,求欧拉函数,求莫比乌斯函数,求对mod的逆元,各种求
筛素数 void shai() { no[1]=true;no[0]=true; for(int i=2;i<=r;i++) { if(!no[i]) p[++p[0]]=i; int j=1, ...
- (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)
题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- POJ 2480 (约数+欧拉函数)
题目链接: http://poj.org/problem?id=2480 题目大意:求Σgcd(i,n). 解题思路: 如果i与n互质,gcd(i,n)=1,且总和=欧拉函数phi(n). 如果i与n ...
- Bzoj-2818 Gcd 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x ...
- hdu 2824 The Euler function(欧拉函数)
题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...
- UVA 10214 Trees in a Wood(欧拉函数)
题意:给你a.b(a<=2000,b<=2000000),问你从原点可以看到范围在(-a<=x<=a,-b<=y<=b)内整数点的个数 题解:首先只需要计算第一象限 ...
- 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)
P2568 GCD 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 输入 ...
随机推荐
- ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)
Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...
- ACM学习历程——UVA127 "Accordian" Patience(栈, 链表)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- BZOJ3219:巡游
浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...
- 学习Tomcat动态加载JSP的Class类
今天在修改项目一个JSP文件时,突然想到Tomat是怎么实现动态实时加载JSP编译后的class类的? 查了半天资料,看了很多文章,终于明白是怎么回事了:ClassLoader,当tomcat发现js ...
- WPF DelegateCommand CanExecute
private DelegateCommand searchCommand; public DelegateCommand SearchCommand { ...
- java基础之框架篇(1)
框架基础反射:反射是Java开发的一类动态相关机制.因为本身Java语言并不是一款动态语言,如果我们想要得到程序动态的效果,因此便引入了反射机制这一概念. 问题:Java中创建实例化对象有哪些方式? ...
- 如何将ajax请求同步化
(function ($) { var a = ['test1', 'test2', 'test3', 'test4']; recursive(3, 'test').done(function (re ...
- sql web Admin 源码.net 升级
http://www.cnblogs.com/foundation/archive/2008/10/07/1305297.html
- 2.6用tr进行转换
tr可以对来自标准输入的内容进行字符替换.字符删除以及重复字符压缩.它可以将一组字符变成另一组字符,因而通常也被称为转换命令. 1.tr只能通过stdin(标准输入),而无法通过命令行参数来接受输入. ...
- 我对微信小程序的一些认识
一. 什么是微信小程序. 微信小程序是指微信公众平台小程序,小程序可以帮助开发者快速的开发小程序,小程序可以在微信内被便捷地获取和传播:是不需要下载和安装既可以使用的应用小程序,是和原有的三种微信公众 ...