-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bryanbcruz
committed
Mar 12, 2019
1 parent
72ef606
commit d81475b
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# [Stars](https://www.urionlinejudge.com.br/judge/pt/problems/view/1233) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
const long long MAX = pow(2, 16); | ||
|
||
list<long long> primes; | ||
|
||
void generate_primes() { | ||
bitset<MAX+1> sieve; | ||
sieve.set(false); | ||
|
||
for (long long i = 2; i <= MAX; i++) { | ||
if (!sieve[i]) { | ||
primes.push_back(i); | ||
|
||
for (long long j = 0; i*i + j*i <= MAX; j++) { | ||
sieve[j*i+i*i] = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
int main(void) { | ||
generate_primes(); | ||
|
||
long long n; | ||
long long result; | ||
|
||
while (~scanf("%lld", &n)) { | ||
result = n; | ||
bool prime = true; | ||
|
||
for(list<long long>::iterator it = primes.begin(); it != primes.end() && *it <= n; it++) { | ||
if (n % *it == 0) { | ||
result /= *it; | ||
result *= *it - 1; | ||
|
||
while (n % *it == 0) n /= *it; | ||
} | ||
} | ||
|
||
if (n > 1) { | ||
result /= n; | ||
result *= n - 1; | ||
} | ||
|
||
long long n_coprimes = result; | ||
long long n_stars = n_coprimes/2; | ||
|
||
printf("%lld\n", n_stars); | ||
} | ||
|
||
return 0; | ||
} | ||
|