Relatives POJ - 2407 (do not hit the table Euler function single request)

Relatives POJ - 2407

Topic links: https://vjudge.net/problem/POJ-2407#author=0

topic:

Given n is a positive integer, the number is less than n is a positive integer n is relatively prime? If there is no integer x> 1, y> 0, z> 0 and such that a = xy b = xz, the two integers a and b are relatively prime.
Input
     There are several test cases. For each test, the standard input comprising n <= 1,000,000,000 rows. In the last case, the row comprising 0.
Output
     for each test case, there should be a single line output to answer the questions posed above.
Sample input

    . 7
    12 is
    0

sample output

    . 6
    . 4

Ideas: start playing table do not find, the data is too large, will be super memory, RE, only a single request

//
// Created by hanyu on 2019/8/9.
//
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include<math.h>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=3e6+7;
#define MAX 0x3f3f3f3f
ll value(ll n)
{
   ll result=n;
   for(int i=2;i*i<=n;i++)
   {
       if(n%i==0)
       {
           result=result/i*(i-1);
           while(n%i==0)
               n/=i;
       }
   }
   if(n>1)
       result=result/n*(n-1);
   return result;
}
int main()
{
    ll n;
    while(~scanf("%lld",&n)&&n)
    {
        printf("%lld\n",value(n));
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/11328908.html