zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    with
    网编
    选课新系统大作业
    网络编程

    知识点
    Python
    学生选课大作业
    理解position与anchorPoint[转]
    毛玻璃效果的简单使用
  • 原文地址:https://www.cnblogs.com/Leozi/p/10835098.html
Copyright © 2011-2022 走看看