(组合数学)不定方程的解+猜测——cf997B

首先要求出三种等价情况

5×1+1×50=1×5+5×105×1+1×50=1×5+5×10
9×5=5×1+4×10
8×5+1×50=9×10
 
那么可以求出三种关于x5,x10的不可行条件
x5 ≥ 1 且 x10 ≥ 5
x≥ 9
x10 ≥ 9
那么只要依次枚举这x5,x10的可能的取值,用不定方程的解数量累计即可
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while (cin >> n)
    {
        long long ans = 0;
        for (int i = 0; i <= 8 && i <= n; i++)
        {
            for (int j = 0; j <= (i == 0 ? 8 : 4) && i + j <= n; j++)
            {
                ans += n + 1 - i - j;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
 

猜你喜欢

转载自www.cnblogs.com/zsben991126/p/11108284.html
今日推荐