HDU 5597 GTW likes function(规律+欧拉函数模板题)——BestCoder Round #66(div.1 div.2)
GTW likes function
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)) .
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)
/************************************************************************/
附上该题对应的中文题
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\geq 1)f(x)=f0(x)=∑k=0x(−1)k22x−2kC2x−k+1k,fn(x)=f(fn−1(x))(n≥1)\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})(1≤n,x≤1012)
对于每组数据输出一行,表示函数\varphi(f_{n}(x))φ(fn(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=0x(−1)k22x−2kC2x−k+1k=x+1,所以显然f_n(x)=n+x+1fn(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}^kan=∑k=0n(−1)k22n−2kC2n−k+1k
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}^kan=22n+∑k=1n(−1)k22n−2k(C2n−kk+C2n−kk−1)=∑k=0n(−1)k22n−2kC2n−kk+∑k=0n−1(−1)k+122(n−1)−2kC2(n−1)−k+1k
设b_n=\sum_{k=0}^{n}(-1)^k2^{2n-2k}C_{2n-k}^kbn=∑k=0n(−1)k22n−2kC2n−kk,则b_n=a_n+a_{n-1}bn=an+an−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)^nbn=22n+∑k=1n−1(−1)k22n−2k(C2n−k−1k+C2n−k−1k−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=0n−1(−1)k22(n−1)−2kC2(n−1)−k+1k+∑k=0n−1(−1)k+122(n−1)−2kC2(n−1)−kk
=4a_n-b_{n-1}=4an−bn−1
得a_n-a_{n-1}=a_{n-1}-a_{n-2}an−an−1=an−1−an−2。因为a_0=1,a_1=1a0=1,a1=1,所以a_n=n+1an=n+1
证明比较费时,打表找规律能很快的得出解,所以本题的关键在于打表找规律。
#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)相关推荐
- HDOJ 5597 GTW likes function (欧拉函数)
GTW likes function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- (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 ...
- HDU 5597 GTW likes function 打表
GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...
- 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\ ...
- hdu 1286 找新朋友 欧拉函数模版题
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Des ...
- 数论 GCD 最大公约数 欧拉函数经典题 洛谷 CF1295D Same GCDs Codeforces1295D
前言 两个月了,我终于更了-- 这两个月忙(chen)于(mi)内(xiang)卷(le),现在终于出新文章啦,(也算兑现了当初的出数论题文章的承诺)~ 不说废话了,今天给大家介绍一道CF/洛谷上的 ...
- hdoj 5597 GTW likes function 【打表找规律】
GTW likes function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- HDU6322 Problem D. Euler Function【欧拉函数+数学规律】
Problem D. Euler Function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java ...
- HDU 1286 找新朋友 (欧拉函数)
找新朋友 http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=8 T ...
最新文章
- oracle包写入程序失败_ORA-12571 : TNS : 包写入程序失败
- 函数的参数与函数的嵌套调用
- 容器和容器镜像的区别,您真的了解吗
- foxpro:将表写入excel
- 浅谈SpringMVC之DispatcherServlet
- HTML5 响应式网页设计之页面美化(二.媒体查询)
- spark学习 小汇集
- Java面试基础部分合集
- AD教程系列 | 3 - 创建原理图库和PCB库
- 手机录音ogg格式怎么转换mp3
- Windows自带的远程协助工具(非远程桌面)
- Altium Designer15安装破解教程
- simulink中找不到CarSim S-Function图标
- 工作人员必备的计算机知识,工作必备计算机技巧知识
- 用Disk Genius检测和修复硬盘坏道
- 计算机面试(考研复试)问题整理
- element-联动下拉框
- 社区电商平台运营中常遇到的一些问题
- linux 替换文件中的字符串
- 图书管理有没有必要使用进出库管理系统?
热门文章
- 霍尔传感器安装位置如何选择
- JAVA中的静态导入
- 解决Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
- java openni rgb显示_Kinect+OpenNI学习笔记之4(OpenNI获取的图像结合OpenCV显示)
- 上海亚商投顾: 市场调整分化 两市成交额再创阶段新低
- 2018阿里广告点击率预估模型---DIN,Tensorflow2.0代码实践,并附上github
- dirmap Use crawl mode 报错
- Thonny-适合初学者的 Python IDE
- 手机淘宝:亿级用户APP的快速运维交付实践
- weblogic之T3反序列化