题目链接:

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. [置顶] 小强的HTML5移动开发之路(9)——坦克大战游戏3

    上一篇我们创建了敌人的坦克和自己的坦克,接下来就应该让坦克发子弹了,我们下面来看一下如何让我们的坦克发出子弹. 前面我们用面向对象的思想对Tank进行了封装,又利用对象冒充实现了我们的坦克和敌人的坦克 ...

  2. mahout算法源码分析之Itembased Collaborative Filtering(四)共生矩阵乘法

    Mahout版本:0.7,hadoop版本:1.0.4,jdk:1.7.0_25 64bit. 经过了SimilarityJob的计算共生矩阵后,就可以开始下面一个过程了,这个过程主要是共生矩阵的乘法 ...

  3. (剑指Offer)面试题20:顺时针打印矩阵

    题目: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字, 例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2, ...

  4. MyEclipse使用总结——使用MyEclipse打包带源码的jar包

    平时开发中,我们喜欢将一些类打包成jar包,然后在别的项目中继续使用,不过由于看不到jar包里面的类的源码了,所以也就无法调试,要想调试,那么就只能通过关联源代码的形式,这样或多或少也有一些不方便,今 ...

  5. PL/pgSQL的anyelement例子

    http://www.postgresonline.com/journal/archives/239-The-wonders-of-Any-Element.html 定义函数 pgsql=# CREA ...

  6. vs2010代码注释自动生成api文档

    最近做了一些接口,提供其他人调用,要写个api文档,可是我想代码注释已经写了说明,能不能直接把代码注释生成api?于是找到以下方法 环境:vs2010 先下载安装Sandcastle 和Sandcas ...

  7. iOS 蒙板,图片叠加显示漏空部分

    懒惰了一个月了,今天写写项目里遇到的一个问题. 图片a 和图片b相互叠加,a图片四周是白色的不规则图形,里面填充黑色. b图片是一张正常图片. 需求是叠加在一起,要求将b图片根据a图片的黑色形状 扣出 ...

  8. Linux makefile 教程 很具体,且易懂

    近期在学习Linux下的C编程,买了一本叫<Linux环境下的C编程指南>读到makefile就越看越迷糊,可能是我的理解能不行. 于是google到了下面这篇文章.通俗易懂.然后把它贴出 ...

  9. 清除DataTable中的空行记录

    第一种方法: string filter = ""; ; i < dt.Columns.Count; i++) { ) filter += dt.Columns[i].Col ...

  10. SVM多分类

    http://www.matlabsky.com/thread-9471-1-1.htmlSVM算法最初是为二值分类问题设计的,当处理多类问题时,就需要构造合适的多类分类器.目前,构造SVM多类分类器 ...