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))(n\geq 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。(1\leq 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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值