UVA 12493 Stars (欧拉函数--求1~n与n互质的个数)
pid=26358">
题目:http://acm.bnu.edu.cn/v3/external/124/12493.pdf
大致题意:圆上有偶数n个点。每m个点连起来。最后能够把全部点串联起来就合法。问有多少个m能够完毕串联,串联后形状同样的算反复
n <2^31
思路:能够写个暴力程序,能够发现仅仅要m与n互质,就能够完毕串联,所以用欧拉函数解决
证明:
设cnt为当第一次达到原点时连接了几个点。
所以有 m*cnt = k*n
得到 cnt = k*n/m
显然要第一次达到原点就是k逐渐增大使k*n/m变为整数的第一个k值, 且由题意必须使cnt = n , 所以m与n互质就可以
所以m的种数就是 phi(n)
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
#define rep(i,n) for ( int i=0; i< int(n); i++ )
using namespace std;
typedef long long ll;
#define X first
#define Y second
typedef pair<int,int> pii;
typedef pair<pii,pii> PII;
template <class T>
inline bool RD(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
template <class T>
inline void PT(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) PT(x / 10);
putchar(x % 10 + '0');
} int euler(int n){ //返回euler(n)
int ans = n;
int num = n;
for(ll i = 2; i*i <= num; i++){
if( num%i == 0){
ans = ans/i*(i-1);
while( num%i == 0) num /= i;
}
}
if(num > 1) ans = ans/num*(num-1);
return ans;
}
int main(){
int n;
while(~scanf("%d",&n)){
printf("%d\n",euler(n)/2);
}
}
UVA 12493 Stars (欧拉函数--求1~n与n互质的个数)的更多相关文章
- 欧拉函数求在1-n-1与n互质的个数
		
long long phi(long long x) { long long res=x,a=x,i; ;i*i<=a;i++) { ) { res=res/i*(i-); ) a=a/i; } ...
 - BZOJ2818: Gcd 欧拉函数求前缀和
		
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 如果两个数的x,y最大公约数是z,那么x/z,y/z一定是互质的 然后找到所有的素数,然后用欧拉函数求一 ...
 - 紫书 例题 10-7 UVa 10820 (欧拉函数)
		
这道题要找二元组(x, y) 满足1 <= x, y <= n 且x与y互素 那么我就可以假设x < y, 设这时答案为f(n) 那么答案就为2 * f(n) +1(x与y反过来就乘 ...
 - GCD - Extreme (II) UVA - 11426(欧拉函数!!)
		
G(i) = (gcd(1, i) + gcd(2, i) + gcd(3, i) + .....+ gcd(i-1, i)) ret = G(1) + G(2) + G(3) +.....+ G(n ...
 - poj 2773 利用欧拉函数求互质数
		
题意:找到与n互质的第 k个数 开始一看n是1e6 敲了个暴力结果tle了,后来发现k达到了 1e8 所以需要用到欧拉函数. 我们设小于n的 ,与n互质的数为 (a1,a2,a3.......a(p ...
 - uva 11426 线性欧拉函数筛选+递推
		
Problem J GCD Extreme (II) Input: Standard Input Output: Standard Output Given the value of N, you w ...
 - 紫书 例题 10-27 UVa 10214(欧拉函数)
		
只看一个象限简化问题,最后答案乘4+4 象限里面枚举x, 在当前这条固定的平行于y轴的直线中 分成长度为x的一段段.符合题目要求的点gcd(x,y) = 1 那么第一段1<= y <= x ...
 - 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}
		
题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...
 - POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)
		
Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...
 
随机推荐
- DNS解析污染原理——要么修改包,要么直接丢弃你的网络包
			
DNS/域名解析 可以看到dns解析是最初的一步,也是最重要的一步.比如访问亲友,要知道他的正确的住址,才能正确地上门拜访. dns有两种协议,一种是UDP(默认),一种是TCP. udp 方式,先回 ...
 - BZOJ 1251 Splay维护序列
			
思路: splay维护序列的裸题 啊woc调了一天 感谢yzy大佬的模板-- //By SiriusRen #include <cstdio> #include <cstring&g ...
 - POJ 3668 枚举?
			
枚举两点,算一下斜率 sort一遍 判个重 输出解 25行 搞定- //By SiriusRen #include <cmath> #include <cstdio> #inc ...
 - C# 引用DLL版本冲突
			
已解决,到官网上下载旧key版本,然后再重定向即可. 手动引用两个版本的DLL错误的原因是我 publicKeyToken 大小写的问题(竟然没校验~~) 但我想不明白,这样搞如果依赖一多的话,甚至那 ...
 - PostgreSQL Replication之第八章 与pgbouncer一起工作(4)
			
8.4 提升性能 从一开始考虑pgbouncer的时候,性能就是一个关键的因素.为了确保高性能,有些问题必须认真对待.首先,确保参与您设置的所有节点相互之间的距离较近.这对于降低网络往返时间有很多的帮 ...
 - Java调用Python遇到的一系列问题与解决方案
			
首先,百度了几个方法 1.用jython里的一个jar包,jython.jar,里面封装了一个专门调用Python的类, 但是不知道为什么我用Java一调用就报错,因此放弃. 2.用runtime ...
 - C#线程安全打开/保存文件对话框
			
在多线程单元模式(MTA)中为应用程序使用.NET OpenFileDialog和SaveFileDialog 下载FileDialogsThreadAppartmentSafe_v1.zip 如果您 ...
 - UI Framework-1: views
			
views Overview and background Windows provides very primitive tools for building user interfaces. Th ...
 - 洛谷 P1501 [国家集训队]Tree II Link-Cut-Tree
			
Code: #include <cstdio> #include <algorithm> #include <cstring> #include <strin ...
 - 【Git 五】TortoiseGit中SSH密钥的配置方法
			
注意:我用的 TortoiseGit 版本是 2.6 的. 一.找到安装目录下的 bin 目录 二.点击 puttygen.exe 三.点击 Generate 生成完毕之后,将 public key ...