/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 5ms 532.0 KiB
#3 Wrong Answer 22ms 532.0 KiB

Code

#include <bits/stdc++.h>
#define int long long
using namespace std;
/*
        OBSERVATIONS:
    FOR EVERY CURRGCD I WILL TAKE CURRG ELEMENTS USING RECURSION AND ADD THEM TO THE RESULT
    AND RETURN AND IN THE MAIN I WILL MULTIPLE THEM WITH RES

*/
const int mod = (int)(1e9 + 7);
int dfs(vector<int> &arr, int index, int k, int currgcd)
{
    if (index >= arr.size())
    {
        if (k == 0)
            return currgcd;
        else
            return 0;
    }
    if (k == 0)
    {
        return currgcd;
    }
    int res = 0;
    // either i skip this element
    res = dfs(arr, index + 1, k, currgcd);
    if (currgcd == -1)
    {
        // first element
        res = (res + dfs(arr, index + 1, k - 1, arr[index]));
    }
    else
    {
        int newgcd = __gcd(currgcd, arr[index]);
        res = (res + dfs(arr, index + 1, k - 1, newgcd));
    }
    return res;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> arr(n);
        for (int i = 0; i < n; i++)
            cin >> arr[i];
        int res = 1;
        for (int currg = 1; currg <= n; currg++)
        {
            int curr = dfs(arr, 0, currg, -1);
            // cout << curr << endl;
            res *= curr;
        }
        cout << res << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1105 Ohh that gcd again
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:19:14
Judged At
2025-09-02 16:19:14
Judged By
Score
10
Total Time
22ms
Peak Memory
532.0 KiB