CF284A Cows and Primitive Roots

我的blog

题目链接:CF284A Cows and Primitive Roots

\[description \]

给出质数p,求模p意义下的原根数量

\[solution \]

这题百度百科上有详细解释原根,在这里:

所以有些大佬认为这题很简单

由里面写的可得,在模p意义下有原根时,他有\(\varphi(\varphi(p))\)个。

\[code \]

#include <cstdio>
#define int long long
#define re register
using namespace std;
template<typename T>
inline void read(T&x)
{
	x=0;
	char s=(char)getchar();
	bool f=false;
	while(!(s>='0'&&s<='9'))
	{
		if(s=='-')
			f=true;
		s=(char)getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=(x<<1)+(x<<3)+s-'0';
		s=(char)getchar();
	}
	if(f)
		x=(~x)+1;
}
inline int euler(int x)
{
	int ans=x;
	for(re int i=2; i*i<=x; ++i)
		if(x%i==0)
		{
			do
				x/=i;
			while(x%i==0);
			ans=ans/i*(i-1);
		}
	if(x>1)
		ans=ans/x*(x-1);
	return ans;
}
signed main()
{
	int p;
	read(p);
	printf("%lld\n",euler(euler(p)));
	return 0;
}
posted @ 2020-04-03 09:34  蒟蒻wjr  阅读(230)  评论(0编辑  收藏  举报