pid=26358">https://uva.onlinejudge.org/index.phpoption=com_onlinejudge&Itemid=8&category=279&page=show_problem&problem=3937

题目: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. 欧拉函数求在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; } ...

  2. BZOJ2818: Gcd 欧拉函数求前缀和

    给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 如果两个数的x,y最大公约数是z,那么x/z,y/z一定是互质的 然后找到所有的素数,然后用欧拉函数求一 ...

  3. 紫书 例题 10-7 UVa 10820 (欧拉函数)

    这道题要找二元组(x, y) 满足1 <= x, y <= n 且x与y互素 那么我就可以假设x < y, 设这时答案为f(n) 那么答案就为2 * f(n) +1(x与y反过来就乘 ...

  4. 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 ...

  5. poj 2773 利用欧拉函数求互质数

    题意:找到与n互质的第 k个数 开始一看n是1e6 敲了个暴力结果tle了,后来发现k达到了 1e8 所以需要用到欧拉函数. 我们设小于n的 ,与n互质的数为  (a1,a2,a3.......a(p ...

  6. uva 11426 线性欧拉函数筛选+递推

    Problem J GCD Extreme (II) Input: Standard Input Output: Standard Output Given the value of N, you w ...

  7. 紫书 例题 10-27 UVa 10214(欧拉函数)

    只看一个象限简化问题,最后答案乘4+4 象限里面枚举x, 在当前这条固定的平行于y轴的直线中 分成长度为x的一段段.符合题目要求的点gcd(x,y) = 1 那么第一段1<= y <= x ...

  8. 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}

    题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...

  9. POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)

    Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...

随机推荐

  1. ubuntu16.04下snort的安装(官方文档安装)(图文详解)

    不多说,直接上干货! 最近为了科研,需要安装和使用Snort. snort的官网 https://www.snort.org/ Snort作为一款优秀的开源主机入侵检测系统,在windows和Linu ...

  2. Hive框架基础(一)

    * Hive框架基础(一) 一句话:学习Hive有毛用? 那么解释一下 毛用: * 操作接口采用类SQL语法,提供快速开发的能力(不会Java也可以玩运算) * 避免了去写MapReduce,减少开发 ...

  3. [UVa11549]Calculator Conundrum

    题目大意:有一个只能显示n位数字的计算器,当溢出时只显示最高的n位. 输入k,要你不断平方,问你计算器显示的最大数是多少. 解题思路:这题的示数肯定会循环,那么我们关键就是找什么时候循环了. 可以用F ...

  4. 《Python生物信息学数据管理》中文PDF+英文PDF+代码

    生物信息学经典资料,解决生物学问题,通过"编程技法"的形式,涵盖尽可能多的组织.分析.表现结果的策略.在每章结尾都会有为生物研究者设计的编程题目,适合教学和自学.由六部分组成:Py ...

  5. [codewars_python]Best travel

    Instructions John and Mary want to travel between a few towns A, B, C ... Mary has on a sheet of pap ...

  6. java回调方法、钩子方法以及模板方法模式

    在面向对象的语言中,回调则是通过接口或抽象类来实现的,我们把实现这种接口的类称为回调类,回调类的对象称为回调对象,其处理事件的方法叫做回调方法.(摘自百度百科) 那么通过上面那句话将百度百科中的&qu ...

  7. ArcGIS api for javascript——查询,立刻打开信息窗口

    描述 本例展示了当一个要素被查询时如何立刻打开一个InfoWindow.信息窗口能被用来将要素的属性格式化成用户易读的格式. 本例中,地图和查询任务都使用ESRI sample server上的服务K ...

  8. 数据迁移工具kettle简单上手

    近期做了不少数据迁移工作,无一例外都是kettle做的,对于这些工具,我认为.够用就好,不用做特别多的研究(当然.除非你是这款工具的忠实粉丝,我相信这种没几个).kettle也不例外.在我看来就是不同 ...

  9. POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)

    POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...

  10. vue2.0-transition动画

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...