第二题答案,可能不是最终答案,但整体思路没动过

#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#define  LL long long
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<unordered_map<int,int>> t(9, unordered_map<int,int>());

    vector<int> nums;

    for (int i = 0; i < n; ++i)
    {
        LL x;
        cin >> x;
        nums.push_back(x);
        LL base = 10;
        for (int j = 0; j < 9; ++j)
        {
            t[j][int((LL)(x)*(LL)(base) % (LL)(7))]++;
            base *= 10;
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i)
    {
        int base = 0;
        int x = nums[i];
        do
        {
            base++;
            x /= 10;
        } while (x > 0);
        int remain = (7 - nums[i] % 7) % 7;
        if (t[base-1][remain] >= 2)
            if (((LL)(nums[i]) * (LL)(pow(10, base))) % 7 == remain)
            {
                cnt += t[base - 1][remain] - 1;
            }
            else
                cnt += t[base - 1][remain];

        else if (t[base-1][remain] < 1)
            continue;
        else
        {
            if (((LL)(nums[i]) * (LL)(pow(10, base))) % 7 == remain)
            {
                continue;
            }
            else
                cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}