Skip to content

Commit

Permalink
add problem
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanbcruz committed Mar 12, 2019
1 parent 72ef606 commit d81475b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions grub/truculencia-2019-02/nt/stars/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# [Stars](https://www.urionlinejudge.com.br/judge/pt/problems/view/1233)
57 changes: 57 additions & 0 deletions grub/truculencia-2019-02/nt/stars/main.cpp
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;
}

0 comments on commit d81475b

Please sign in to comment.