首页 > 其他分享 >POJ 2407 Relatives

POJ 2407 Relatives

时间:2022-11-09 19:40:37浏览次数:36  
标签:integers const int 2407 Relatives POJ ans include define


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 there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz.


Input



There are several test cases. For each test case, standard input contains a line with n <= 1,000,000,000. A line containing 0 follows the last case.


Output



For each test case there should be single line of output answering the question posed above.


Sample Input



7 12 0


Sample Output



6

4


根号效率求欧拉函数

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-4;
const int INF = 0x7FFFFFFF;
const int mod = 998244353;
const int N = 20;
int n;

int main()
{
while (scanf("%d", &n), n)
{
int ans = 1;
for (int i = 2; i*i <= n; i++)
{
if (n % i) continue;
n /= i; ans *= i - 1;
while (!(n % i)) ans *= i, n /= i;
}
printf("%d\n", n > 1 ? ans * (n - 1) : ans);
}
return 0;
}



标签:integers,const,int,2407,Relatives,POJ,ans,include,define
From: https://blog.51cto.com/u_15870896/5838599

相关文章

  • POJ 3970 Party
    DescriptionTheCEOofACM(AssociationofCryptographicMavericks)organizationhasinvitedallofhisteamstotheannualall-handsmeeting,beingaver......
  • SPOJ LCS Longest Common Substring
    DescriptionAstringisfinitesequenceofcharactersoveranon-emptyfinitesetΣ.Inthisproblem,Σisthesetoflowercaseletters.Substring,alsocalled......
  • SPOJ LCS2 Longest Common Substring II
    DescriptionAstringisfinitesequenceofcharactersoveranon-emptyfinitesetΣ.Inthisproblem,Σisthesetoflowercaseletters.Substring,alsocalled......
  • POJ 3458 Colour Sequence
    DescriptionWehaveapileofcardsconsistingof100cardsthatarecolouredonbothsides.Thereisafinitenumberofcolours(atmost26).Inadditionthe......
  • SPOJ 705 New Distinct Substrings
    DescriptionGivenastring,weneedtofindthetotalnumberofitsdistinctsubstrings.InputT-numberoftestcases.T<=20;Eachtestcaseconsistsofonestr......
  • POJ 1743 Musical Theme
    DescriptionAmusicalmelodyisrepresentedasasequenceofN(1<=N<=20000)notesthatareintegersintherange1..88,eachrepresentingakeyonthepi......
  • 究竟什么是POJO?
    POJO(PlainOldJavaObject)这种叫法是MartinFowler、RebeccaParsons和JoshMacKenzie在2000年的一次演讲的时候提出来的。     我在做J2EE培训中发现我的......
  • POJ3061 Subsequence
    思路:尺取法注意本题目中所有的内容全部是证书,这就为我们维护了一个很好的单调性.考虑最暴力的\(\mathcalO(n^3)\)的做法,就是枚举起点,终点,然后分别求和.但是......
  • POJ-1018
    POJ-1018(现在好像过不了)题意目前有一个公司需要购进宽带设备,每种设备有多款机器供选择,每种设备都需购进一台,现给出每台设备的带宽p与价格q,要求选择设备的最小带宽\(min(......
  • POJ-3737
    POJ-3737题意给出一个圆锥的表面积,求最大体积。思路显然,得到底面积的半径后,一切都能得到。在我们慢慢延长半径时,发现不满足线性,而是单峰函数。故三分。圆锥复习Code......