Contest

El contest lo puedes encontrar aquí.

Los enunciados en pdf los puedes encontrar en Inglés y en Español.

Estas son las soluciones:

A: A + B = C

#include <bits/stdc++.h>

using namespace std;

int main () {
  double a, b, c;
  cin >> a >> b >> c;
  if (fabs(a + b - c) < 1e-6) cout << "YES" << '\n';
  else cout << "NO" << '\n';
}

Author: TISparta

B: Quick Game

#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
    if(a >= m) a %= m;
    if(b >= m) b %= m;
    if(a < 0) a += m;
    if(b < 0) b += m;
    ll res = a+b;
    if(res >= m or res <= -m) res %= m;
    if(res < 0) res += m;
    return res;
}

ll mul(ll a, ll b, ll m = MOD){
    if(a >= m) a %= m;
    if(b >= m) b %= m;
    if(a < 0) a += m;
    if(b < 0) b += m;
    ll res = a*b;
    if(res >= m or res <= -m) res %= m;
    if(res < 0) res += m;
    return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
    ll res = 1LL;
    a = a%m;
    while(b){
        if(b&1) res = mul(res,a,m);
        b >>= 1;
        a = mul(a,a,m);
    }
    return res;
}

ll fastexp(ll a, ll b){
    ll res = 1LL;
    while(b){
        if(b&1) res = res*a;
        b >>= 1;
        a *= a;
    }
    return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
    if(a == 0){
        *x = 0;
        *y = 1;
        return b;
    }
    int x1, y1;
    int gcd = gcdExtendido(b%a,a,&x1,&y1);
    
    *x = y1-(b/a)*x1;
    *y = x1;
    return gcd;
}

int modInverso(int a, int m){
    int x, y;
    int g = gcdExtendido(a,m,&x,&y);
    if(g!=1) return -1;
    else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 1000000+5;

int n;
char s[N];

int main(){
    scanf("%s",s);
    n = strlen(s);
    int mask = 0;
    for(int i=0; i<n; i++){
        int c = s[i] - 'a';
        mask ^= 1<<c;
    }
    int ans = max(1, (int)__builtin_popcount(mask));
    printf("%d\n",ans);
    return 0;
}

Autor: racsosabe

C: Integer Circumradius

#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b, c;
    int nc = 1;
    int t;
    cin >> t;
    while (cin >> a >> b) {
        assert(1 <= a and a <= 20000);
        assert(1 <= b and b <= 20000);
        if (a > b) swap(a, b);
        bool ok = 1;
        for (int x = b - a + 1; x < a + b; ++x) {
            long long t = 1ll * a * b * x;
            long long q1 = 1ll * (a + b + x) * (a + b - x);
            long long q2 = 1ll * (a - b + x) * (-a + b + x);
            long long sq = sqrt(q1 * q2);
            while (sq * sq > q1 * q2) sq -= 1;
            while (sq * sq < q1 * q2) sq += 1;
            if (sq * sq == q1 * q2) {
                if (t % sq == 0) {
                    cout << x << endl;
                    ok = 0;
                    break;
                }
            }
        }
        if (ok) {
            cout << -1 << endl;
        }
    }
    return 0;
}

Autor: Fischer

D: The answer to the life

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = 1e11;
vector <ll> arr;

void backtrack (ll num) {
  if (num > N) {
    return;
  }
  if (num != 0) {
    arr.push_back(num);
  }
  backtrack(num * 10 + 4);
  backtrack(num * 10 + 2);
}

int main () {
  backtrack(0);
  int q;
  cin >> q;
  while (q--) {
    ll l, r;
    cin >> l >> r;
    int ans = 0;
    for (ll elem: arr) {
      ans += (l <= elem and elem <= r);
    }
    if (ans == 42) cout << "YES\n";
    else cout << "NO\n";
  }
  return (0);
}

Autor: TISparta

E: Carmichael Attack

#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
    if(a >= m) a %= m;
    if(b >= m) b %= m;
    if(a < 0) a += m;
    if(b < 0) b += m;
    ll res = a+b;
    if(res >= m or res <= -m) res %= m;
    if(res < 0) res += m;
    return res;
}

ll mul(ll a, ll b, ll m = MOD){
    if(a >= m) a %= m;
    if(b >= m) b %= m;
    if(a < 0) a += m;
    if(b < 0) b += m;
    ll res = a*b;
    if(res >= m or res <= -m) res %= m;
    if(res < 0) res += m;
    return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
    ll res = 1LL;
    a = a%m;
    while(b){
        if(b&1) res = mul(res,a,m);
        b >>= 1;
        a = mul(a,a,m);
    }
    return res;
}

ll fastexp(ll a, ll b){
    ll res = 1LL;
    while(b){
        if(b&1) res = res*a;
        b >>= 1;
        a *= a;
    }
    return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
    if(a == 0){
        *x = 0;
        *y = 1;
        return b;
    }
    int x1, y1;
    int gcd = gcdExtendido(b%a,a,&x1,&y1);
    
    *x = y1-(b/a)*x1;
    *y = x1;
    return gcd;
}

int modInverso(int a, int m){
    int x, y;
    int g = gcdExtendido(a,m,&x,&y);
    if(g!=1) return -1;
    else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 6000000+5;

int n;
int pf[N];

void init(){
    for(int i=1; i<N; i++){
        pf[i] = i;
    }
    for(int i=2; i*i<=N; i++){
        if(pf[i] == i){
            for(int j = i*i; j < N; j+=i){
                pf[j] = i;
            }
        }
    }
}

bool primo(int x){
    for(int i=2; i*i<=x; i++){
        if(x % i == 0) return false;
    }
    return true;
}

bool testBases(int x){
    for(int i=2; i<x; i++){
        if(gcd(x,i) > 1) continue;
        int r = pow_mod(i,x-1,x);
        if(r != 1) return false;
    }
    return true;
}

bool carmichael(int x){
    if(x < N){
        if(pf[x] == x) return false;
    }
    else if(primo(x)) return false;
    return testBases(x);
}

int main(){
    ri(n);
    init();
    while(!carmichael(n)) n += 1;
    printf("%d\n",n);
    return 0;
}

Autor: racsosabe

F. Divisible Subarray

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int last = 1, cnt = 0, mx = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x % last == 0) cnt += 1;
        else cnt = 1;
        mx = max(mx, cnt);
        last = x;
    }
    cout << mx << endl;
    return 0;
}

Autor: Fischer

G: 3-sum

#include <bits/stdc++.h>

using namespace std;

int main () {
  int n, target;
  cin >> n >> target;
  vector <int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(begin(arr), end(arr));
  for (int x = 0; x < n; x++) {
    int l = 0;
    int r = n - 1;
    int new_target = target - arr[x];
    while (l < r) {
      if (arr[l] + arr[r] == new_target) {
        if (arr[l] != arr[x] and
            arr[r] != arr[x] and
            arr[l] != arr[r]) {
          vector <int> ans = {arr[x], arr[l], arr[r]};
          sort(begin(ans), end(ans));
          cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << '\n';
          return (0);
        }
        l++;
      } else if (arr[l] + arr[r] < new_target) {
        l++;
      } else {
        r--;
      }
    }
  }
  cout << -1 << '\n';
  return (0);
}

Autor: TISparta

H. Rare Factorial

#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
    if(a >= m) a %= m;
    if(b >= m) b %= m;
    if(a < 0) a += m;
    if(b < 0) b += m;
    ll res = a+b;
    if(res >= m or res <= -m) res %= m;
    if(res < 0) res += m;
    return res;
}

ll mul(ll a, ll b, ll m = MOD){
    if(a >= m) a %= m;
    if(b >= m) b %= m;
    if(a < 0) a += m;
    if(b < 0) b += m;
    ll res = a*b;
    if(res >= m or res <= -m) res %= m;
    if(res < 0) res += m;
    return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
    ll res = 1LL;
    a = a%m;
    while(b){
        if(b&1) res = mul(res,a,m);
        b >>= 1;
        a = mul(a,a,m);
    }
    return res;
}

ll fastexp(ll a, ll b){
    ll res = 1LL;
    while(b){
        if(b&1) res = res*a;
        b >>= 1;
        a *= a;
    }
    return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
    if(a == 0){
        *x = 0;
        *y = 1;
        return b;
    }
    int x1, y1;
    int gcd = gcdExtendido(b%a,a,&x1,&y1);
    
    *x = y1-(b/a)*x1;
    *y = x1;
    return gcd;
}

int modInverso(int a, int m){
    int x, y;
    int g = gcdExtendido(a,m,&x,&y);
    if(g!=1) return -1;
    else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

ll L, M;

bool valid(int k, int n){
    int A = 1, B = 1;
    for(int i=2; i<=k; i++) A *= i;
    int total = 1<<n;
    for(int i=0; i<n; i++){
        B *= (total - fastexp(2,i));
    }
    return A == B;
}

int main(){
    rll2(L,M);
    int ans = 0;
    for(int k=1; k <= min(6LL,L); k++){
        for(int n = 1; n <= min(6LL,M); n++){
            if(valid(k,n)){
                ans = add(ans,1);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Autor: racsosabe

I. Hyper Sum

#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> A, B, C;
    auto add = [](set<int>& S, int x) -> void {
        S.emplace(x);
    };
    for (int i = 1; i*i <= max({a, b, c}); ++i) {
        if (a % i == 0) add(A, i), add(A, a/i);
        if (b % i == 0) add(B, i), add(B, b/i);
        if (c % i == 0) add(C, i), add(C, c/i);
    }
    bool sum = false;
    for (int x : A){
        for (int y : B) {
            sum |= C.count(x + y);
            if (sum){
                break;
            }
        }
        if(sum) break;
    }
    if (sum) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Autor: Fischer