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;
}

 

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

 

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

 

#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;
}

 

相关文章:

  • 2022-12-23
  • 2021-07-20
  • 2021-08-22
  • 2021-09-04
  • 2021-07-01
  • 2021-08-14
  • 2021-12-31
  • 2021-08-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2022-02-12
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案