zoukankan      html  css  js  c++  java
  • Croc Champ 2013

    问满足a^3 + b^3 + c^3 + n = (a+b+c)^3 的 (a,b,c)的个数

    可化简为 n = 3*(a + b) (a + c) (b + c)

    于是 n / 3 = (a + b)(a + c) (b + c)

    令x = a + b,y = a + c,z = b + c,s = n / 3

    s = xyz

    并且令x <= y <= z,于是我们解s = xyz这个方程,可以枚举x,y得到z。

    得到(x,y,z)后便可以得到a,b,c但可能有不符合条件的三元组,化简系数矩阵

    1  1  0    由于枚举时已满足x <= y <= z   2  0  0 x + y - z >= 0,即 x + y >= z

    1  0  1                                      1  0  1

    0  1  1                    0  1  1

    另外如果x = y = z时此时只贡献了一个答案,如果x = y || y = z 答案只贡献了3个

    其余贡献了6个

    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cassert>
    #include <cstring>
    #include <set>
    #include <map>
    #include <list>
    #include <queue>
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    #include <stack>
    using namespace std;
    typedef long long ll;
    #define T int t_;Read(t_);while(t_--)
    #define dight(chr) (chr>='0'&&chr<='9')
    #define alpha(chr) (chr>='a'&&chr<='z')
    #define INF (0x3f3f3f3f)
    #define maxn (2000005)
    #define maxm (10005)
    #define mod 1000000007
    #define ull unsigned long long
    #define repne(x,y,i) for(int i=(x);i<(y);++i)
    #define repe(x,y,i) for(int i=(x);i<=(y);++i)
    #define repde(x,y,i) for(int i=(x);i>=(y);--i)
    #define repdne(x,y,i) for(int i=(x);i>(y);--i)
    #define ri register int
    inline void Read(int &n){char chr=getchar(),sign=1;for(;!dight(chr);chr=getchar())if(chr=='-')sign=-1;
        for(n=0;dight(chr);chr=getchar())n=n*10+chr-'0';n*=sign;}
    inline void Read(ll &n){char chr=getchar(),sign=1;for(;!dight(chr);chr=getchar())if
        (chr=='-')sign=-1;
        for(n=0;dight(chr);chr=getchar())n=n*10+chr-'0';n*=sign;}
    ll n;
    int powx(int c,ll t){
        ll l = 1,r = sqrt(t);
        while(l <= r){
            ll mid = (l + r) >> 1,s = 1;
            repe(1,c,i) s *= mid;
            if(s > t) r = mid - 1;
            else if(s < t) l = mid + 1;
            else return (int)mid;
        }
        return (int)r;
    }
    int main()
    {
        //freopen("a.in","r",stdin);
        //freopen("b.out","w",stdout);
        Read(n);
        if(n % 3){
            puts("0");
            return 0;
        }
        n /= 3;
        int lix = powx(3,n);
        int ans = 0;
        repe(2,lix,x){
            if(n % x) continue;
            ll nx = n / x;
            int liy = powx(2,nx);
            repde(liy,x,y){
                if(nx % y) continue;
                int z = nx / y;
                if(x + y <= z) break;
                if((x + y + z) & 1) continue;
                if(x == y && y == z) ++ans;
                else if(x == y || y == z) ans += 3;
                else ans += 6;
            }
        }
        cout << ans << endl;
        return 0;
        /*
        t = a + b
        (a-b)^2 + 4s/t = k^2
        */
    }
  • 相关阅读:
    ES6新特性:使用export和import实现模块化
    常见Linux/Unix开发辅助命令什锦
    Spark高速上手之交互式分析
    Lua中的元表与元方法
    explicit 构造函数
    【排序】基数排序(计数排序、桶排序)
    拓展训练—心得体会
    poj3411--Paid Roads(bfs+状压)
    点击单选button后的文字就可以选定相应单选button
    hdu 2349 最小生成树
  • 原文地址:https://www.cnblogs.com/zhuiyicc/p/9750426.html
Copyright © 2011-2022 走看看