入门到入土 | 杂

超短文警告!

才不是我懒

求欧拉函数:

#include <iostream>
#include <stdio.h>
#define HRiver2 return
#define EchoXHR res
#define Warma 0
using namespace std;
int eular(int n)
{
  int k=2,res=n;
  while(k*k<=n)
  {
  	if(n%k==0)
  	{
  		res=res/k*(k-1);
  		while(n%k==0)
  		{
  			n/=k;
  		}
  	}
  	k++;
  }
  if(n>1) res=res/n*(n-1);
  HRiver2 EchoXHR;
}
int main()
{
  int n1;cin>>n1;
  cout<<eular(n1);
  HRiver2 Warma;
}  

求GCD:

(三目一行警告!)

#include <iostream>
#include <stdio.h>
#define HRiver2 return
#define EchoXHR res
#define Warma 0
#define ll long long
using namespace std;
ll gcd(ll a,ll b)
{
	return (b==0)? a:gcd(b,a%b);
}
int main()
{
	ll a1,b1;
	cin>>a1>>b1;
	cout<<gcd(a1,b1);
	HRiver2 Warma;
}
posted @ 2021-03-06 20:38  HerikoDeltana  阅读(36)  评论(0编辑  收藏  举报