POJ_2407 Relatives 【欧拉函数裸题】】的更多相关文章

一.题目 Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz. Input There are several test c…
给整数N(1 ≤ N ≤ 1000000000),求小于N的与N不互素的所有正整数的和. 思路:1.用欧拉函数求出小于N的与N互素的正整数的个数: 2.若 p 与 N 互素,则 N-p 必与 N 互素(若 N%p==0 ,则 ( N , N-p )=p): 3.据此求出 小于N的与N互素的正整数 的和,用 小于N的所有正整数 的和减去之即可. #include<iostream> #include<cstdio> using namespace std; long long n,s…
http://poj.org/problem?id=2407 题意:多组数据,每次输入一个数 ,求这个数的欧拉函数 int euler_phi(int n){//单个欧拉函数 int m=(int)sqrt(n+0.5); int ans=n; ;i<=m;i++)){ ans=ans/i*(i-); )n/=i; } )ans=ans/n*(n-); } 单个欧拉函数 int phi[maxn]; void phi_table(int n){//函数表 ;i<=n;i++)phi[i]=;…
Relatives Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz. Input There are several t…
题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 166 Accepted Submission(s): 96   Problem Description The Euler function phi is an important kind of function in number theory…
题目大意 给定一个正整数n,要求你求出所有小于n的正整数当中与n互质的数的个数 题解 欧拉函数模板题~~~因为n过大~~~所以直接用公式求 代码: #include<iostream> #include<cmath> #include<cstdio> using namespace std; int euler_phi(int n) { int m=(int)sqrt(n+0.5); int ans=n; ; i<=m; i++) ) { ans=ans/i*(i…
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> using namespace std; ;//最大范围 int phi[maxx]; void phi_table(){ ;i<=maxx;i++)phi[i]=; phi…
找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description 新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来.   Input 第一行是测试数据的组…
题目链接:https://vjudge.net/problem/POJ-2407 题意:给出n,求0..n-1中与n互质的数的个数. 思路:欧拉函数板子题,先根据唯一分解定理求出n的所有质因数p1,p2,...,pn,然后根据Φ(m)=m*∏(1-1/pi)计算即可. AC代码: #include<cstdio> using namespace std; int n,ans; int main(){ while(scanf("%d",&n),n){ ans=n; ;…
Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Description Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if ther…