Submission #924005

# Submission time Handle Problem Language Result Execution time Memory
924005 2024-02-08T08:34:49 Z Ianis Binary Subsequences (info1cup17_binary) C++17
12.9 / 100
19 ms 4188 KB
#ifdef LOCAL
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <random>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#else
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define cerr if (false) cerr 
#define endl '\n'
#endif
 
#define fi first
#define se second
 
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
 
#define lsb(x) (x & (-x))
 
#define bit(mask, i) (((mask) >> (i)) & 1)
#define popcount(x) __builtin_popcount(x)
 
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
 
using namespace std;
 
template <typename T>
bool ckmax(T &a, T b) { return a < b ? a = b, true : false; }
template <typename T>
bool ckmin(T &a, T b) { return a > b ? a = b, true : false; }
 
using ll = long long;
using pii = pair<int, int>;
 
const int NMAX = 1e6+10;
const int MOD  = 1e9+7;
 
int n;
int phi[NMAX];
 
void read() {
   cin >> n;
}
 
void precalc() {
   for (int i = 1; i <= NMAX; i++) {
      phi[i] = i;
   }

   for (int i = 2; i <= NMAX; i++) {
      if (phi[i] == i) {
         for (int j = i; j <= NMAX; j += i)
            phi[j] = (phi[j] / i) * (i - 1);
      }
   }
}
 
void solve() {
   cout << phi[n + 2] << endl << -1 << endl;
}
 
signed main() {
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#endif
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   int t = 1;
   cin >> t;
 
   precalc();
   while (t--) {
      read();
      solve();
   }
 
   return 0;
}

Compilation message

binary.cpp: In function 'void precalc()':
binary.cpp:55:14: warning: iteration 1000009 invokes undefined behavior [-Waggressive-loop-optimizations]
   55 |       phi[i] = i;
      |       ~~~~~~~^~~
binary.cpp:54:22: note: within this loop
   54 |    for (int i = 1; i <= NMAX; i++) {
      |                    ~~^~~~~~~
binary.cpp:59:16: warning: iteration 1000008 invokes undefined behavior [-Waggressive-loop-optimizations]
   59 |       if (phi[i] == i) {
      |           ~~~~~^
binary.cpp:58:22: note: within this loop
   58 |    for (int i = 2; i <= NMAX; i++) {
      |                    ~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 19 ms 4188 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -