View Code of Problem 3938

#include <iostream>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <bitset>
#include <sstream>

using namespace std;


typedef long long ll;
const ll mod = 1e9 + 7;

ll R[101] = {2, 3, 5, 7, 11, 13, 17, 19};
int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        ll x, y, n, m;
        scanf("%lld%lld%lld%lld", &x, &y, &n, &m);
        if (n < x || !y)
        {
            printf("(ToT)\n");
            //fout << "(ToT)" << endl;
            continue;
        }
        int k = -1;
        while (k + 1 < 8 && R[k + 1] <= m) k++;
        k++;
        ll cnt = 0;
        for(int i = 1; i < (1 << k); i++) {
            ll r = 1;
            ll r0 = 0;
            for(int j = 0; j < k; j++) {
                if((i >> j) & 1) {
                    r0++;
                    r = r * (R[j] ? R[j] : 1);
                }
            }
            if(r0 & 1) cnt += n / r;
            else cnt -= n / r;
        }
        if(n - cnt + min(y, cnt) >= x) printf("(*^_^*)\n");
        else printf("(ToT)\n");
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3938