题目链接:

GTW likes function

Time Limit: 4000/2000 MS (Java/Others)   

 Memory Limit: 131072/131072 K (Java/Others)

Problem Description
 
Now you are given two definitions as follows.

f(x)=∑xk=0(−1)k22x−2kCk2x−k+1,f0(x)=f(x),fn(x)=f(fn−1(x))(n≥1)

Note that φ(n) means Euler’s totient function.(φ(n)is an arithmetic function that counts the positive integers less than or equal to n that are relatively prime to n.)

For each test case, GTW has two positive integers — n and x, and he wants to know the value of the function φ(fn(x)).

 
Input
 
There is more than one case in the input file. The number of test cases is no more than 100. Process to the end of the file.

Each line of the input file indicates a test case, containing two integers, n and x, whose meanings are given above. (1≤n,x≤1012)

 
Output
 
In each line of the output file, there should be exactly one number, indicating the value of the function φ(fn(x)) of the test case respectively.
 
Sample Input
 
1 1
2 1
3 2
 
Sample Output
 
2
2
2
 
题意:
 
给这么一个函数,问euler(fn(x))为多少;
 
思路:
 
发现f0(x)=x+1;fn(x)=f(fn-1(x))=f0(fn-1(x))=fn-1(x)+1=f0(x)+n=x+n+1;
再就是O(sqrt(n))复杂度找到euler(x+n+1);
 
AC代码:
 
//#include <bits/stdc++.h>

#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} LL n,x; int main()
{
while(cin>>n>>x)
{
LL sum=n+x+,ans;
ans=sum;
for(LL i=;i*i<=n+x+;i++)
{
if(sum%i==)
{
ans=ans/i*(i-);
while(sum%i==)sum/=i;
}
}
if(sum>)ans=ans/sum*(sum-);
cout<<ans<<"\n";
} return ;
}

hdu-5597 GTW likes function(欧拉函数+找规律)的更多相关文章

  1. HDU 5597 GTW likes function 欧拉函数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5597 题意: http://bestcoder.hdu.edu.cn/contests/contes ...

  2. 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)

    题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...

  3. hdu 2824 The Euler function(欧拉函数)

    题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...

  4. HDU 5597 GTW likes function 打表

    GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...

  5. hdu 2824 The Euler function 欧拉函数打表

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. HDU - 2824 The Euler function 欧拉函数筛 模板

    HDU - 2824 题意: 求[a,b]间的欧拉函数和.这道题卡内存,只能开一个数组. 思路: ϕ(n) = n * (p-1)/p * ... 可利用线性筛法求出所有ϕ(n) . #include ...

  7. 【poj 2478】Farey Sequence(数论--欧拉函数 找规律求前缀和)

    题意:定义 Fn 序列表示一串 <1 的分数,分数为最简分数,且分母 ≤n .问该序列的个数.(2≤N≤10^6) 解法:先暴力找规律(代码见屏蔽处),发现 Fn 序列的个数就是 Φ(1)~Φ( ...

  8. HDU 6237.A Simple Stone Game-欧拉函数找素因子 (2017中国大学生程序设计竞赛-哈尔滨站-重现赛)

    A Simple Stone Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  9. HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)

    6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...

随机推荐

  1. TemplateBinding vs TemplatedParent【PluraSight】

    TemplateBinding:TemplateBinding是一个Markup Extension

  2. Array--Good parts

    js数组没有上届 --如果你用大于或等于当前length的数字作为下标来存储一个元素,那么length会被增大以容纳新元素,不会发生数组越界. 数组也是对象 --可以添加属性.a["name ...

  3. flash 定义主舞台窗口大小

    1:[SWF(width=100 height=100)] 写在主类上面2:设置stageScaleMode属性为false;

  4. 如何实现Conditional Include

    本文转载:http://www.cnblogs.com/brusehht/archive/2010/09/01/1814962.html 问题描述 有些朋友希望使用这样的一种查询方式,比如要查询Mov ...

  5. 你尽力了么===BY cloudsky

    /////////////////////////////////////////////////////////////////////////// 这是我的同事alert7在他主页上转scz的&l ...

  6. Codeforces Round #310 (Div. 1) B. Case of Fugitive set

    B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...

  7. android仿win8 metro磁贴布局

    代码下载     //更新代码,   这里是更新后的代码 //////////////////////// 1,含一个图片无限滚动的控件,自己实现的 2.可新增删除每个磁贴 3.来个图片吧 ////* ...

  8. 教你用Cocosdx导出安卓安装文件(.apk)(一)

    我也是刚弄出来,过程可能有点混乱和不具体,我尽我所能写完整.各位看官多多包涵 设备环境: 我所用的是mac 10.8.5    64位 Cocosdx-3.0rc2 xcode 5.0 一.准备 ND ...

  9. MySQL中内存分为全局内存和线程内存

    首先我们来看一个公式,MySQL中内存分为全局内存和线程内存两大部分(其实并不全部,只是影响比较大的 部分): 复制代码 代码如下: per_thread_buffers=(read_buffer_s ...

  10. win7+iss7的配置,以及如何在本地IIS服务器挂载一个网站

    虽然学过在XP安装IIs服务器和在IIS服务器挂载网站的东西,但是win7和XP的方式还是有许多不同的.废话不说直接进入正题 在本地安装IIS服务器 在IIS服务器中添加你的项目 将你项目的首页设置为 ...