紫书 例题 10-7 UVa10820 欧拉函数
来源:互联网 发布:安卓手机优化 编辑:程序博客网 时间:2024/05/25 05:35
题意:求1~n之间共有多少对互质的数
分析:如果用普通方法一个一个判断,时间复杂度是O(n^2),会超时。但是可以利用欧拉函数和筛法在O(nloglogn)时间内把50000内与每个数互质的正整数的个数求出来。当求有多少对时,只需令sum[n]*2 —1即可。
解题方法:
////Created by BLUEBUFF 2016/1/11//Copyright (c) 2016 BLUEBUFF.All Rights Reserved//#pragma comment(linker,"/STACK:102400000,102400000")//#include <ext/pb_ds/assoc_container.hpp>//#include <ext/pb_ds/tree_policy.hpp>//#include <ext/pb_ds/hash_policy.hpp>//#include <bits/stdc++.h>#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <time.h>#include <cstdlib>#include <cstring>#include <complex>#include <sstream> //isstringstream#include <iostream>#include <algorithm>using namespace std;//using namespace __gnu_pbds;typedef long long LL;typedef unsigned long long uLL;typedef pair<int, LL> pp;#define REP1(i, a, b) for(int i = a; i < b; i++)#define REP2(i, a, b) for(int i = a; i <= b; i++)#define REP3(i, a, b) for(int i = a; i >= b; i--)#define CLR(a, b) memset(a, b, sizeof(a))#define MP(x, y) make_pair(x,y)template <class T1, class T2>inline void getmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void getmin(T1 &a, T2 b) { if (b<a)a = b; }const int maxn = 50010;const int maxm = 1e5+5;const int maxs = 10;const int maxp = 1e3 + 10;const int INF = 1e9;const int UNF = -1e9;const int mod = 1e9 + 7;const int rev = (mod + 1) >> 1; // FWTconst double PI = acos(-1);//headvoid phi_table(int n, int *phi){ for(int i = 2; i <= n; i++) phi[i] = 0; phi[1] = 1; for(int i = 2; i <= n; i++){ if(!phi[i]){ for(int j = i; j <= n; j += i){ if(!phi[j]) phi[j] = j; phi[j] = phi[j] / i * (i - 1); } } }}int phi[maxn], sum[maxn];int main(){ phi_table(maxn - 1, phi); sum[0] = 0; for(int i = 1; i < maxn; i++) sum[i] = sum[i - 1] + phi[i]; int n; while(scanf("%d", &n) != EOF && n) { printf("%d\n", 2 * sum[n] - 1); } return 0;}
0 0
- 紫书 例题 10-7 UVa10820 欧拉函数
- uva10820(欧拉函数)
- uva10820(数论 +欧拉函数)
- uva10820(欧拉函数)
- 例10-7 uva10820(欧拉)
- uva10820 - Send a Table 欧拉函数
- uva10820(欧拉函数,排列组合)
- 例题10-7 交表 UVa10820
- UVA10820 - Send a Table(欧拉函数)
- uva10820 交表(欧拉定理应用)
- 【数论】Send a Table, UVa10820 【线性筛法】【欧拉函数】
- 欧拉函数的证明以及应用(附POJ例题)
- 欧拉函数与欧拉函数的递推总结+例题POJ2478
- UVa10820
- 欧拉回路及例题
- UVA10200-Prime Time/HDU2161-Primes,例题讲解,牛逼的费马小定理和欧拉函数判素数。
- 紫书章六例题16 单词 UVA 10129(欧拉道路)
- ACM--steps--2.1.7--欧拉函数
- windows7 在cmd中执行php脚本
- Spring Security-- 验证码功能的实现
- linux服务器rm删除文件后磁盘空间没释放
- Go与并发模型
- MySQLCluster数据节点内存空间释放
- 紫书 例题 10-7 UVa10820 欧拉函数
- oc-Foundation_02_NSArray
- java POI创建Excel的单元格并填值
- Android自定义状态栏颜色与应用标题栏颜色一致
- 十进制转二进制(easy)
- mysql获取时间
- 两只老虎改编(天线宝宝版)
- AngularJS入门教程
- idea常用快捷键