Croc Champ 2013 - Round 2 C. Cube Problem

问满足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=;for(;!dight(chr);chr=getchar())if(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
inline void Read(ll &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if
(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
ll n;
int powx(int c,ll t){
ll l = ,r = sqrt(t);
while(l <= r){
ll mid = (l + r) >> ,s = ;
repe(,c,i) s *= mid;
if(s > t) r = mid - ;
else if(s < t) l = mid + ;
else return (int)mid;
}
return (int)r;
}
int main()
{
//freopen("a.in","r",stdin);
//freopen("b.out","w",stdout);
Read(n);
if(n % ){
puts("");
return ;
}
n /= ;
int lix = powx(,n);
int ans = ;
repe(,lix,x){
if(n % x) continue;
ll nx = n / x;
int liy = powx(,nx);
repde(liy,x,y){
if(nx % y) continue;
int z = nx / y;
if(x + y <= z) break;
if((x + y + z) & ) continue;
if(x == y && y == z) ++ans;
else if(x == y || y == z) ans += ;
else ans += ;
}
}
cout << ans << endl;
return ;
/*
t = a + b
(a-b)^2 + 4s/t = k^2
*/
}
上一篇:java 设计模式


下一篇:如何降低移动APP的开发成本