HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数

GTW likes function

 
 
 
 
 Memory Limit: 131072/131072 K (Java/Others)
问题描述
现在给出下列两个定义:
	f(x)=f_{0}(x)=sum_{k=0}^{x}(-1)^{k}2^{2x-2k}C_{2x-k+1}^{k},f_{n}(x)=f(f_{n-1}(x))(ngeq 1)f(x)=f0​​(x)=k=0x​​(1)k​​22x2k​​C2xk+1k​​,fn​​(x)=f(fn1​​(x))(n1)

	varphi(n)φ(n)为欧拉函数。指的是不超过nn的与nn互质的正整数个数。

对于每组数据,GTW有两个正整数n,xn,x,现在他想知道函数varphi(f_{n}(x))φ(fn​​(x))的值。
输入描述
输入有多组数据,不超过100组。每数据输入一行包含2个整数组nn和xx。(1leq n,x leq 10^{12})(1n,x1012​​)
输出描述
对于每组数据输出一行,表示函数varphi(f_{n}(x))φ(fn​​(x))的值。
输入样例
1 1
2 1
3 2
输出样例
2
2
2

 题解:按照给出的公式打表,你就会发现其实就是求 n+1+x的欧拉函数值,写个欧拉函数就好了,注意是long long

//meek///#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll;

const int N=1005000+100;
const int inf = 99999999;
const int mod= 1000000007;

ll phi(ll n)
{
    ll res=n;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            res=res-res/i;
            while(n%i==0)
                n/=i;
        }
    }
    if(n>1)
        res=res-res/n; //可能还有大于sqrt(n)的素因子
    return res;
}
int main() {

   ll n,x;
    while(scanf("%I64d%I64d",&n,&x)!=EOF) {
            int ans=0;
         cout<<phi(x+n+1)<<endl;
    }
    return 0;
}
代码
原文地址:https://www.cnblogs.com/zxhl/p/5042627.html