uva10820(简单数学题)
2015-06-12 19:19
274 查看
题目的大概意思是有两个变量x,y,然后x,y都是小于n的,有一个函数f(x,y),另外f(x*k,y*k) = f(x,y),问f(x,y)在x,y都不超过n的时候的取值个数,很明显的就是记下来的想x,y必定是互素的,当然有一个另外就是1,1。
求解,很明显的就是转化为欧拉phi函数问题,求出1-n中与n互素的个数,然后x,y可以互换位置,求得的结果要乘以2。
求解,很明显的就是转化为欧拉phi函数问题,求出1-n中与n互素的个数,然后x,y可以互换位置,求得的结果要乘以2。
#include "stdio.h" #include "string.h" #include "math.h" #include <string> #include <queue> #include <stack> #include <vector> #include <map> #include <algorithm> #include <iostream> using namespace std; #define MAXM 1 #define MAXN 1 #define max(a,b) a > b ? a : b #define min(a,b) a < b ? a : b #define Mem(a,b) memset(a,b,sizeof(a)) int Mod = 1000000007; double pi = acos(-1.0); double eps = 1e-6; typedef struct{ int f,t,w,next; }Edge; Edge edge[MAXM]; int head[MAXN]; int kNum; typedef long long LL; void addEdge(int f, int t, int w) { edge[kNum].f = f; edge[kNum].t = t; edge[kNum].w = w; edge[kNum].next = head[f]; head[f] = kNum ++; } LL phi[50005]; int N; void func(){ Mem(phi, 0); phi[1] = 1; for(int i = 2; i <= 50000; i ++){ if( !phi[i] ){ // phi[i] = i; for(int j = i; j <= 50000; j += i){ if( !phi[j] ) phi[j] = j; phi[j] = phi[j] / i * (i - 1); } } } for(int i = 2; i <= 50000; i ++){ phi[i] = 2 * phi[i] + phi[i-1]; } } int main() { // freopen("d:\\test.txt", "r", stdin); func(); while(cin>>N){ if( N < 1 ) break; cout<<phi <<endl; } return 0; }
相关文章推荐
- LeetCode 226 Invert Binary Tree
- rsync
- jq实现批量图片上传
- 使用方法拦截器MethodInterceptor和AOP统一处理log
- [hdu5266]区间LCA
- 读后感
- 今天做一个winform,想直接把窗体改成输出类库,其他地方直接调结果总提示不能注册组件,回来调度,可以,总结,windows还是直接用新建的类型项目,改容易出错
- 遇到的多条件贝叶斯概率问题
- 诸葛:数据科学家所需具备的技能
- 浅克隆与深克隆
- 【干货】产品经理如何写好一份数据分析报告
- bzoj 1455 可并堆+并查集
- MongoDB 2.6 兼容性改变 -- db.collection.aggregate()改变
- 漂亮实用的提示框插件SweetAlert
- Jquery ajax调用webservice总结
- orgChart生成组织结构图应用
- 编程之美之买书问题
- Toad for IBM DB2 Freeware v6.0.0.373
- Factorial Trailing Zeroes
- PKU Online Judge POJ流传最广的分类,ACMer必备