UVA11296 Counting Solutions to an Integral Equation【数学】

Given, n, count the number of solutions to the equation x + 2y + 2z = n, where x, y, z, n are non negative integers.
Input
There is at most 1500 inputs. Each input is n (n < 1000001) on a single line.
Output
For each input, output the number of solutions on a single line.
Sample Input
2
3
Sample Output
3
3

问题链接UVA11296 Counting Solutions to an Integral Equation
问题简述:(略)
问题分析
    x, y, z, n是非负整数,且n < 1000001,x+2y+2z=n。假设x=0,那么2*(y+z)的范围是[0,n],即y+z的范围是[0,n/2]。y+z确定后x也就确定了。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11296 Counting Solutions to an Integral Equation */

#include <iostream>

using namespace std;

int main()
{
    long long n;
    while(~scanf("%lld", &n)) {
        n = n / 2 + 1;
        printf("%lld\n", n * (n + 1) / 2);
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10375266.html