x+2y+3z=n非负整数解

 

#include <iostream>
#include <string.h>
#include <stdio.h>
 
using namespace std;
typedef long long LL;
 
LL work(LL n)
{
    LL ans = 0;
    for(int k = 0; k <= n / 3; k++)
        ans += (n - 3 * k) / 2 + 1;
    return ans;
}
 
int main()
{
    LL n;
    while(cin>>n)
        cout<<work(n)<<endl;
    return 0;
}

 

 

 

#include <iostream>
#include <string.h>
#include <stdio.h>
 
using namespace std;
typedef long long LL;
 
LL work(LL n)
{
    LL k = n / 3;
    LL t = (k + 1) * n - 3 * k * (k + 1) / 2;
    LL ans = k + 1;
    if(k & 1) t -= (k + 1) / 2;
    else if(n & 1) t -= (k / 2 + 1);
    else t -= k / 2;
    t >>= 1;
    return ans + t;
}
 
int main()
{
    LL n;
    while(cin>>n)
        cout << work(n) << endl;
    return 0;
}

 

posted @ 2019-05-08 22:11  Leozi  阅读(667)  评论(0编辑  收藏  举报