SGU102 Coprimes
来源:互联网 发布:永琪和知画圆房视频 编辑:程序博客网 时间:2024/05/21 18:43
SGU102 Coprimes
题目大意
输入一个正整数N
输出小于等于N并且与N互素的正整数的个数
算法思路
欧拉函数
时间复杂度: O(N‾‾√)
代码
/** * Copyright (c) 2015 Authors. All rights reserved. * * FileName: 102.cpp * Author: Beiyu Li <sysulby@gmail.com> * Date: 2015-05-21 */#include <bits/stdc++.h>using namespace std;#define rep(i,n) for (int i = 0; i < (n); ++i)#define For(i,s,t) for (int i = (s); i <= (t); ++i)#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)typedef long long LL;typedef pair<int, int> Pii;const int inf = 0x3f3f3f3f;const LL infLL = 0x3f3f3f3f3f3f3f3fLL;int main(){ int n; scanf("%d", &n); int res = n; for (int i = 2; i * i <= n; ++i) if (n % i == 0) { res = res / i * (i - 1); while (n % i == 0) n /= i; } if (n != 1) res = res / n * (n - 1); printf("%d\n", res); return 0;}
0 0
- SGU102 Coprimes
- sgu102:Coprimes
- SGU102 Coprimes
- SGU102 Coprimes
- SGU102 Coprimes
- SGU102 Coprimes
- SGU102——Coprimes (又见欧几里得)
- SGU102
- sgu102
- sgu102
- Coprimes
- 102. Coprimes
- sgu102-欧拉函数
- NYOJ 479 Coprimes
- [SGU]102. Coprimes
- Sgu 102. Coprimes
- sgu 102 Coprimes 互质
- SGU 102 - Coprimes(简单)
- 最大流算法 Dinic HDU 1532
- Java多线程系列--“基础篇”03之 Thread中start()和run()的区别
- UITabbar系统默认蓝色修改
- 导出时注意时间格式
- 关于adapter布局中有Button控件时,导致ListView的onItemClick无法触发的问题
- SGU102 Coprimes
- 解决listview嵌套时的高度问题
- strcpy函数
- Android ActivityThread(主线程或UI线程)简介
- android 电容屏(四):驱动调试之驱动程序分析篇 -- FocalTech
- JavaScript 标准参考教程
- this class is not key value coding-compliant for the key xx
- 素数与RSA
- 解决iscroll的超链接问题(针对iscroll4)