hdoj 5597 GTW likes function 【打表找规律】
来源:互联网 发布:安卓黑科技软件网站 编辑:程序博客网 时间:2024/06/08 02:33
GTW likes function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 243 Accepted Submission(s): 134
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)) .
Note that
For each test case, GTW has two positive integers —
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)
Each line of the input file indicates a test case, containing two integers,
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 12 13 2
Sample Output
222
问题描述
现在给出下列两个定义:f(x)=f0(x)=∑k=0x(−1)k22x−2kC2x−k+1k,fn(x)=f(fn−1(x))(n≥1)φ(n)为欧拉函数。指的是不超过n的与n互质的正整数个数。对于每组数据,GTW有两个正整数n,x,现在他想知道函数φ(fn(x))的值。
输入描述
输入有多组数据,不超过100组。每数据输入一行包含2个整数组n和x。(1≤n,x≤1012)
输出描述
对于每组数据输出一行,表示函数φ(fn(x))的值。
打表代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (50000+1)#define MAXM (5000000000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;LL C[110][110];void getC(){ for(int i = 0; i <= 50; i++) C[i][0] = 1, C[i][i] = 1; for(int i = 1; i <= 50; i++) for(int j = 1; j < i; j++) C[i][j] = C[i-1][j-1] + C[i-1][j];}LL Pow(LL a, LL n){ LL ans = 1; while(n) { ans *= a; n--; } return ans;}LL f(LL x){ LL ans = 0; for(LL k = 0; k <= x; k++) { if(k & 1LL) ans -= Pow(2, 2*x-2*k) * C[2*x-k+1][k]; else ans += Pow(2, 2*x-2*k) * C[2*x-k+1][k]; } return ans;}int main(){ getC(); for(LL i = 1; i <= 20LL; i++) Pl(f(i)); return 0;}
规律明显为f(x) = x + 1,这样f n(x) = x + n + 1。下面就是求解欧拉函数了。
AC代码:数据很大,先除后乘。
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (50000+1)#define MAXM (5000000000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;LL euler(LL n){ LL ans = n; for(LL i = 2; i * i <= n; i++) { if(n % i == 0) { ans = ans / i * (i-1); while(n % i == 0) n /= i; } } if(n > 1) ans = ans / n * (n-1); return ans;}int main(){ LL n, x; while(scanf("%lld%lld", &n, &x) != EOF){ printf("%I64d\n", euler(n+x+1)); } return 0;}
0 0
- hdoj 5597 GTW likes function 【打表找规律】
- HDOJ 5597 GTW likes function(规律+欧拉函数)
- hdoj-【5597 GTW likes function】
- hdoj GTW likes function 5597 (裸欧拉函数)
- HDOJ 5597 GTW likes function (欧拉函数)
- hdu 5597 GTW likes function
- hdu-5597 GTW likes function
- HDU 5597 GTW likes function
- hdu 5597 GTW likes function
- 杭电5597GTW likes function
- HDU 5597 GTW likes function(规律+欧拉函数模板题)——BestCoder Round #66(div.1 div.2)
- HDOJ--5595--GTW likes math
- hdoj-5595-GTW likes math
- hdu 5597GTW likes function(欧拉函数)
- hdu 5597 GTW likes function(欧拉函数)
- hdoj GTW likes math 5595 (暴力)
- HDOJ 5596 GTW likes gt(巧解)
- HDOJ 5596 GTW likes gt 【思维 】
- 【重磅干货】看了此文,Oracle SQL优化文章不必再看!
- 【层级结构】Ext.js5应用层级结构介绍
- MockServer的测试思想与实现
- 【100题纪念】【有趣的算法】【leetcode题解】【E】【84】Merge Sorted Array
- 玩转四旋翼无人机(DJI OnBoard SDK ROS)
- hdoj 5597 GTW likes function 【打表找规律】
- loadrunner脚本录制为空的解决方法
- php内核探索-常量
- Android蓝牙BLE之RSSI数据的读写(1)
- 抛弃幻想,谈谈现实中的数据科学家
- android Ndk ADT编译环境搭建
- 行为型模式(二)
- 第七周项目5 排队看病模拟
- fadora21 声卡驱动消失问题