Cod sursa(job #2791933)

Utilizator DragosC1Dragos DragosC1 Data 31 octombrie 2021 14:10:16
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <fstream>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

long long a[277000];
const int n = 3;
char s[20];
int cnt;

long long get_nr() {
    int i, len;
    long long nr = 0;
    len = strlen(s);
    for (i = 0; i < len; i++)
        if (isdigit(s[i]))
            nr = nr * 10 + s[i] - '0';
    return nr;
}

void read() {
    int i, Q, st, dr, mij;
    long long x;
    FILE *f;
    f = fopen("dtcsu.in", "r");
    for (i = 1; i <= n; i++) {
        fgets(s, 20, f);
        a[i] = get_nr();
    }
    sort(a + 1, a + n + 1);
    fgets(s, 20, f);
    Q = get_nr();
    for (i = 1; i <= Q; i++) {
        fgets(s, 20, f);
        x = get_nr();
        while (x % 2 == 0)
            x /= 2;
        while (x % 3 == 0)
            x /= 3;
        while (x % 5 == 0)
            x /= 5;
        while (x % 7 == 0)
            x /= 7;
        while (x % 11 == 0)
            x /= 11;
        if (x == 1)
            cnt++;
        // st = 1, dr = n;
        // while (st <= dr) {
        //     mij = (st + dr) / 2;
        //     if (a[mij] == x) {
        //         cnt++;
        //         break;
        //     }
        //     else if (a[mij] < x)
        //         st = mij + 1;
        //     else dr = mij - 1;
        // }
    }
}

void output() {
    ofstream g("dtcsu.out");
    g << cnt;
    g.close();
}

int main() {
    read();
    output();
    return 0;
}