Submission #47385780


Source Code Expand

#include<iostream>
#include<map>
#include<cstring>
using namespace std;

const int MOD = 998244353;

long long n;
int x, y, z;
map<long long, map<long long, map<long long, long long>>> dp[70][12][12][12];

int get_gcd(int a, int b)
{
    int temp;
    
    while(a % b)
    {
        temp = a % b;
        a = b;
        b = temp;
    }
    
    return b;
}

int get_lcm(int a, int b)
{
    return a / get_gcd(a, b) * b;
}

long long recur(long long cur, int cbit, long long a, long long b, long long c)
{
    long long ret = 0;
    long long da, db, dc;
    
    if(a > n || b > n || c > n) return 0;
    if(cur == 0) return a % x == 0 && b % y == 0 && c % z == 0;
    
    da = min(n - a, 2 * cur - 1);
    db = min(n - b, 2 * cur - 1);
    dc = min(n - c, 2 * cur - 1);
    
    if(dp[cbit][a % x][b % y][c % z][da][db].find(dc) != dp[cbit][a % x][b % y][c % z][da][db].end()) return dp[cbit][a % x][b % y][c % z][da][db][dc];
        
    ret += recur(cur >> 1, cbit - 1, a + cur, b, c + cur);
    ret += recur(cur >> 1, cbit - 1, a, b + cur, c + cur);
    ret += recur(cur >> 1, cbit - 1, a + cur, b + cur, c);
    ret += recur(cur >> 1, cbit - 1, a, b, c);
        
    return dp[cbit][a % x][b % y][c % z][da][db][dc] = ret % MOD;
}

int main()
{
    long long ans;
    
    cin >> n >> x >> y >> z;
    
    ans = recur(1LL << 61, 61, 0, 0, 0);
    
    ans += MOD;
    ans -= (n / get_lcm(x, y)) % MOD;
    
    ans += MOD;
    ans -= (n / get_lcm(y, z)) % MOD;
    
    ans += MOD;
    ans -= (n / get_lcm(x, z)) % MOD;
    
    ans += MOD;
    ans--;
    
    cout << ans % MOD;
}

Submission Info

Submission Time
Task F - Nim
User gojib2002
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1666 Byte
Status AC
Exec Time 17 ms
Memory 15860 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 44
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 6 ms 10480 KiB
random_02.txt AC 6 ms 10944 KiB
random_03.txt AC 5 ms 9924 KiB
random_04.txt AC 5 ms 9808 KiB
random_05.txt AC 4 ms 9416 KiB
random_06.txt AC 4 ms 9424 KiB
random_07.txt AC 4 ms 9528 KiB
random_08.txt AC 5 ms 10104 KiB
random_09.txt AC 5 ms 10224 KiB
random_10.txt AC 4 ms 9352 KiB
random_11.txt AC 4 ms 9276 KiB
random_12.txt AC 5 ms 9828 KiB
random_13.txt AC 5 ms 10148 KiB
random_14.txt AC 4 ms 9272 KiB
random_15.txt AC 5 ms 10056 KiB
random_16.txt AC 4 ms 9368 KiB
random_17.txt AC 4 ms 9276 KiB
random_18.txt AC 7 ms 11488 KiB
random_19.txt AC 4 ms 9408 KiB
random_20.txt AC 4 ms 9276 KiB
random_21.txt AC 4 ms 9272 KiB
random_22.txt AC 8 ms 11624 KiB
random_23.txt AC 4 ms 9356 KiB
random_24.txt AC 12 ms 13480 KiB
random_25.txt AC 10 ms 12544 KiB
random_26.txt AC 5 ms 9864 KiB
random_27.txt AC 11 ms 13016 KiB
random_28.txt AC 7 ms 10912 KiB
random_29.txt AC 5 ms 9828 KiB
random_30.txt AC 17 ms 15860 KiB
random_31.txt AC 6 ms 10164 KiB
random_32.txt AC 4 ms 9664 KiB
random_33.txt AC 5 ms 10172 KiB
random_34.txt AC 4 ms 9452 KiB
random_35.txt AC 10 ms 13024 KiB
random_36.txt AC 6 ms 10492 KiB
random_37.txt AC 4 ms 9292 KiB
random_38.txt AC 4 ms 9172 KiB
random_39.txt AC 8 ms 11608 KiB
random_40.txt AC 4 ms 9516 KiB
random_41.txt AC 4 ms 9692 KiB
sample_01.txt AC 4 ms 9108 KiB
sample_02.txt AC 4 ms 9216 KiB
sample_03.txt AC 4 ms 9332 KiB