x^z + y^z + x*y*z = k; (x < y ,z > 1),给你一个k问有多少组解.
思路:
暴力枚举z,y,然后二分查找x.注意一点最好用快速幂,别用pow,不然有可能会超时,如果先把z=2的处理了会快一点.应该会0ms.....
#include<stdio.h> __int64 quickp(__int64 a,__int64 n) { __int64 aa=1; while(n) { if(n&1) aa*=a; a*=a; n>>=1; } return aa; } int main () { __int64 x ,y ,z ,i ,j ,k; __int64 low ,up ,mid; while(~scanf("%I64d" ,&k) && k) { __int64 sum = 0; for(z = 2 ;z <= 31 ;z ++) { for(y = 2 ;y <= 46341 ;y ++) { if(quickp(y ,z) > k) break; low = 1; up = y-1; __int64 mk = 0; while(low <= up) { mid = (low + up) / 2; if(quickp(mid ,z) + quickp(y ,z) + mid*y*z >= k) { up = mid - 1; mk = mid; } else low = mid + 1; } if(quickp(mk ,z) + quickp(y ,z) + mk*y*z == k) sum ++; } } printf("%I64d " ,sum); } return 0; }