GTW likes function

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
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
Source
BestCoder Round #66 (div.2)

/************************************************************************/

附上该题对应的中文题

GTW likes function

 
 Time Limit: 4000/2000 MS (Java/Others)
 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)=f​0​​(x)=∑​k=0​x​​(−1)​k​​2​2x−2k​​C​2x−k+1​k​​,f​n​​(x)=f(f​n−1​​(x))(n≥1)\varphi(n)φ(n)为欧拉函数。指的是不超过nn的与nn互质的正整数个数。对于每组数据,GTW有两个正整数n,xn,x,现在他想知道函数\varphi(f_{n}(x))φ(f​n​​(x))的值。
输入描述
输入有多组数据,不超过100组。每数据输入一行包含2个整数组nn和xx。(1\leq n,x \leq 10^{12})(1≤n,x≤10​12​​)
输出描述
对于每组数据输出一行,表示函数\varphi(f_{n}(x))φ(f​n​​(x))的值。
输入样例
1 1
2 1
3 2
输出样例
2
2
2
/****************************************************/

出题人的解题思路:

GTW likes function

由打表找规律可得,\sum_{k=0}^{x}(-1)^{k}2^{2x-2k}C_{2x-k+1}^{k}=x+1∑​k=0​x​​(−1)​k​​2​2x−2k​​C​2x−k+1​k​​=x+1,所以显然f_n(x)=n+x+1f​n​​(x)=n+x+1,因此直接求\varphi(n+x+1)φ(n+x+1)。时间效率O(T\sqrt{n})O(T√​n​​​)

严格证明:

设a_n=\sum_{k=0}^{n}(-1)^k2^{2n-2k}C_{2n-k+1}^ka​n​​=∑​k=0​n​​(−1)​k​​2​2n−2k​​C​2n−k+1​k​​

a_n=2^{2n}+\sum_{k=1}^{n}(-1)^k2^{2n-2k}(C_{2n-k}^k+C_{2n-k}^{k-1})=\sum_{k=0}^{n}(-1)^k2^{2n-2k}C_{2n-k}^k+\sum_{k=0}^{n-1}(-1)^{k+1}2^{2(n-1)-2k}C_{2(n-1)-k+1}^ka​n​​=2​2n​​+∑​k=1​n​​(−1)​k​​2​2n−2k​​(C​2n−k​k​​+C​2n−k​k−1​​)=∑​k=0​n​​(−1)​k​​2​2n−2k​​C​2n−k​k​​+∑​k=0​n−1​​(−1)​k+1​​2​2(n−1)−2k​​C​2(n−1)−k+1​k​​

设b_n=\sum_{k=0}^{n}(-1)^k2^{2n-2k}C_{2n-k}^kb​n​​=∑​k=0​n​​(−1)​k​​2​2n−2k​​C​2n−k​k​​,则b_n=a_n+a_{n-1}b​n​​=a​n​​+a​n−1​​

b_n=2^{2n}+\sum_{k=1}^{n-1}(-1)^k2^{2n-2k}(C_{2n-k-1}^k+C_{2n-k-1}^{k-1})+(-1)^nb​n​​=2​2n​​+∑​k=1​n−1​​(−1)​k​​2​2n−2k​​(C​2n−k−1​k​​+C​2n−k−1​k−1​​)+(−1)​n​​

=4\sum_{k=0}^{n-1}(-1)^k2^{2(n-1)-2k}C_{2(n-1)-k+1}^k+\sum_{k=0}^{n-1}(-1)^{k+1}2^{2(n-1)-2k}C_{2(n-1)-k}^k=4∑​k=0​n−1​​(−1)​k​​2​2(n−1)−2k​​C​2(n−1)−k+1​k​​+∑​k=0​n−1​​(−1)​k+1​​2​2(n−1)−2k​​C​2(n−1)−k​k​​

=4a_n-b_{n-1}=4a​n​​−b​n−1​​

得a_n-a_{n-1}=a_{n-1}-a_{n-2}a​n​​−a​n−1​​=a​n−1​​−a​n−2​​。因为a_0=1,a_1=1a​0​​=1,a​1​​=1,所以a_n=n+1a​n​​=n+1

证明比较费时,打表找规律能很快的得出解,所以本题的关键在于打表找规律。

一开始觉得这题有毒,谁都知道应该要先求出fn(x)的值,但是求这个是难点,但是没办法,该求的还是得求,于是将样例中的几组求了一下(比较傻,没想到打表)

故可大胆猜测出
然后用一下欧拉函数的模板就ok了

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 50005;
const int M = 710;
const int inf = 1000000000;
const int mod = 1000000007;
__int64 euler(__int64 n)
{__int64 ans=1;__int64 i;for(i=2;i*i<=n;i++){if(n%i==0){n/=i;ans*=i-1;while(n%i==0){n/=i;ans*=i;}}}if(n>1)ans*=n-1;return ans;
}
int main()
{__int64 n,x;while(~scanf("%I64d%I64d",&n,&x))printf("%I64d\n",euler(n+x+1));return 0;
}

菜鸟成长记

HDU 5597 GTW likes function(规律+欧拉函数模板题)——BestCoder Round #66(div.1 div.2)相关推荐

  1. HDOJ 5597 GTW likes function (欧拉函数)

    GTW likes function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  2. (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)

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

  3. HDU 5597 GTW likes function 打表

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

  4. HDU 5597 GTW likes function

    题意: 现在给出下列两个定义: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\ ...

  5. hdu 1286 找新朋友 欧拉函数模版题

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Des ...

  6. 数论 GCD 最大公约数 欧拉函数经典题 洛谷 CF1295D Same GCDs Codeforces1295D

    ​前言 两个月了,我终于更了-- 这两个月忙(chen)于(mi)内(xiang)卷(le),现在终于出新文章啦,(也算兑现了当初的出数论题文章的承诺)~ 不说废话了,今天给大家介绍一道CF/洛谷上的 ...

  7. hdoj 5597 GTW likes function 【打表找规律】

    GTW likes function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  8. HDU6322 Problem D. Euler Function【欧拉函数+数学规律】

    Problem D. Euler Function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java ...

  9. HDU 1286 找新朋友 (欧拉函数)

    找新朋友 http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=8 T ...

最新文章

  1. oracle包写入程序失败_ORA-12571 : TNS : 包写入程序失败
  2. 函数的参数与函数的嵌套调用
  3. 容器和容器镜像的区别,您真的了解吗
  4. foxpro:将表写入excel
  5. 浅谈SpringMVC之DispatcherServlet
  6. HTML5 响应式网页设计之页面美化(二.媒体查询)
  7. spark学习 小汇集
  8. Java面试基础部分合集
  9. AD教程系列 | 3 - 创建原理图库和PCB库
  10. 手机录音ogg格式怎么转换mp3
  11. Windows自带的远程协助工具(非远程桌面)
  12. Altium Designer15安装破解教程
  13. simulink中找不到CarSim S-Function图标
  14. 工作人员必备的计算机知识,工作必备计算机技巧知识
  15. 用Disk Genius检测和修复硬盘坏道
  16. 计算机面试(考研复试)问题整理
  17. element-联动下拉框
  18. 社区电商平台运营中常遇到的一些问题
  19. linux 替换文件中的字符串
  20. 图书管理有没有必要使用进出库管理系统?

热门文章

  1. 霍尔传感器安装位置如何选择
  2. JAVA中的静态导入
  3. 解决Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
  4. java openni rgb显示_Kinect+OpenNI学习笔记之4(OpenNI获取的图像结合OpenCV显示)
  5. 上海亚商投顾: 市场调整分化 两市成交额再创阶段新低
  6. 2018阿里广告点击率预估模型---DIN,Tensorflow2.0代码实践,并附上github
  7. dirmap Use crawl mode 报错
  8. Thonny-适合初学者的 Python IDE
  9. 手机淘宝:亿级用户APP的快速运维交付实践
  10. weblogic之T3反序列化