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 
#include 
#include 
#include 
#include 
#include <set>
#include 
#include 
#include 
#include <string>
#include 
#include 
#include 
#include 
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*/
}

 

转载于:https://www.cnblogs.com/zhuiyicc/p/9750426.html


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部