摘要: 题目大意:求小于n的gcd(i,n)大于1的个数;题解:欧拉函数直接求gcd(i,n)==1的个数 用n减即可#include int eular(int n){ int ret=1,i; for(i=2;i*i1) ret*=n-1; return ret;}int main(){ int n; while(scanf("%d",&n),n!=0)printf("%d\n",n-eular(n)-1); return 0;} 阅读全文
posted @ 2014-04-07 15:10 forever97 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 筛法计算欧拉函数#include #include using namespace std;const int maxn=3000005;long long phi[maxn];int main(){ int i,j,a,b; for(i=1;i<=maxn;i++) phi[i]=i; for(i=2;i<=maxn;i+=2) phi[i]/=2; for(i=3;i<=maxn;i+=2)if(phi[i]==i){ for(j=i;j<=maxn;j+=i) phi[j]=phi[j]/i*(i-1); } while(sca... 阅读全文
posted @ 2014-04-07 14:51 forever97 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 单个欧拉函数int eular(int n){ int ret=1,i; for(i=2;i*i1) ret*=n-1; return ret;}筛法求欧拉函数#include #include using namespace std;const int maxn=3000005;... 阅读全文
posted @ 2014-04-07 14:37 forever97 阅读(1107) 评论(0) 推荐(0) 编辑
摘要: 题解:计算凸包周长#include #include #include const int size=1000; using namespace std; struct pint{int x,y;}x[size]; int n,l,ans[size],cnt,sta[size],tail; bool cmp(pint a,pint b){return (a.y1 && !crossleft(x[sta[tail-1]],x[sta[tail-2]],x[i])) tail--; sta[tail++]=i; } for... 阅读全文
posted @ 2014-04-07 14:16 forever97 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 题解:先算出凸包,然后枚举凸包上的点计算即可#include #include #include #include using namespace std;const int N = 50005;const double eps = 1e-8;struct point {int x,y;}p[N], stack[N];bool isZero(double x){return (x>0?x:-x)<eps;}double dis(point A, point B){return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}int cr 阅读全文
posted @ 2014-04-07 13:54 forever97 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 增量法的最小包围圈算法,不会……#include #include #include #include #include using namespace std;const double EPS = 1e-10;inline int sgn(double x) { return (x > EPS) - (x 1 && sgn(crossDet(ch[m - 2], ch[m - 1], pt[i])) = 0; i--) { while (m > k && sgn(crossDet(ch[m - 2], ch[m - 1], pt[i])) 1) m 阅读全文
posted @ 2014-04-07 13:42 forever97 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 题解:每放一根棍子,都判断一下它与它前面的且在顶端的棍子是否相交,相交的话则将相应的棍子从解空间中除去。#include const double eps=1e-14; const int maxn=1e5+10; struct node{double x1,y1,x2,y2;int w;}e[maxn],f[maxn]; double cross(double x1,double y1,double x2,double y2){return x1*y2-x2*y1;} int find(node a,node b){ double c[4]; c[0]=cros... 阅读全文
posted @ 2014-04-07 13:28 forever97 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 题解:计算凸包……#include #include #include #include using namespace std; struct node{int x,y;}vex[1005],stackf[1005]; bool cmp1(node a,node b){ if(a.y==b.y)return a.x0?1:0; } int main(){ int t; while(scanf("%d",&t),t!=0){ for(int i=0;i=1&&cross(stackf[top-1],stackf[top],vex... 阅读全文
posted @ 2014-04-07 13:13 forever97 阅读(162) 评论(0) 推荐(0) 编辑