欧拉函数

Coach Yu has lots of bags, every bag has its number. And what is more, he wants to send these bags to acm team-member. But he requires that if you get the bag and its number is b, you need to count how many number smaller than b and co-prime with b. If you can't count it, he won't send the bag to you.
However, G.D.R and Hacb learn the The Euler function to solve the problem. And they are so friendly that they like to share the function to you, so you can get the bag.
The Euler function is:
F(b) = b *( 1 - 1/p1) ( 1 - 1/p2)......(1-1/pn)
Notes: pi is the ith Prime factors of b, and there will be no such i and j which i<>j but pi=pj.

Input

A number b as describe . 0<b<10^12. The input will end by a number 0.

Output

Output F(b) on a line.
If n=1, you should just output 0.

Sample Input

7
0

Sample Output

6

Hint: f(7) = 7 * (1 - 1/7) = 6


 

欧拉函数

#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
int main()
{
	long long  n;
	while(cin>>n&&n)
	{
		long long  temp=n;
		long long  ans=n;
		for(long long i=2;i*i<=temp;i++)
		{
			if(temp%i==0)
			{
				ans=(ans-ans/i);		
				while(temp%i==0)
				{
					temp=temp/i;	
				}
			}
			
		}
		if(temp!=1)
			ans=(ans-ans/temp);
		printf("%lld\n",ans);
		
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值