HDU 4282 A very hard mathematic problem (12 Tianjin network competition-mathematics)

Source: Internet
Author: User

Link: Click here ~~
Question:
The formula x ^ z + y ^ z + x * y * z = k indicates the number in a given int range.
Evaluate the total number of groups of solutions for x, y, and z. (0 <x <y, z> 1)
Solution:
I have been entangled in this question for two days. I finally caught the mistake today.
It is not difficult to observe the formula. Obviously, when z is larger, the value of x and y is smaller.
Because y is equal to 2 at the minimum, there are 2 ^ z <k, and k <2 ^ 31, so there are z <31.
1. When z = 2, the left side of the formula can be (x + y) ^ 2 = k.
Therefore, when k is the complete number of records, (x, y) can be solved.
If m ^ 2 = k, the problem is equivalent to finding the number of groups for the solution x + y = m (x <y.
It is easy to conclude that when m is an even number, the number of solution groups is m/2-1; when m is an odd number, the number of solution groups is (S-1)/2.
2. Then consider when z> = 3.
When z = 3, x and y may obtain the maximum value. After a slight calculation, the maximum value of y is 1290.xx, and the value is M.
Then the complexity of enumerating x and z is changed to O (M * 30), which is about O (10 ^ 4 ).
If you enumerate y directly, the complexity is O (M ^ 2*30), which is roughly O (10 ^ 7), slightly larger. (However, it can be 140 ms ac ).
Is there a good way?
Obviously, after x and z are determined, the formula about y increases monotonically, so we can divide it into two parts and reduce the complexity to O (M * logM * 30 ), it is about O (10 ^ 5 ). (15 ms ac ).
The first time I handed in with a trumpet, it took 0 MS, and then it was ranked rank1. O (partition _ partition) O...
Ps: The idea has always been correct, but yesterday WA had a day.
Pay attention to some details. At the second point, the right boundary of my y is always M when z = 3. This greedy and convenient approach will cause a problem.
That is, when z gradually increases, many values in the binary interval will overflow the long range, leading to incorrect judgment size.
Fortunately, when a value overflows, it becomes negative. Therefore, we can determine whether the value overflows based on whether the value is negative. If overflow occurs, it is directly equivalent to greater.
[Cpp]
# Include <stdio. h>
# Include <math. h>
 
Typedef _ int64 LL;
 
Int k, x, y, z;
 
LL xz, yz;
 
LL myPow (int a, int n)
{
LL ans =;
While (-- n)
Ans * =;
Return ans;
}
 
LL fun (int Y)
{
Return xz + yz + x * Y * z;
}
 
Bool FindIt (int l, int r)
{
While (l <= r)
{
Int mid = (l + r)/2;
Yz = myPow (mid, z );
LL f = fun (mid );
If (f = k)
Return true;
If (f <0 | f> k)
R = mid-1;
Else
L = mid + 1;
}
Return false;
}
 
Int main ()
{
While (scanf ("% d", & k), k)
{
Int ans = 0;
Int sqrt (k * 1.0 );
If (sq * sq = k)
Ans + = (sq-1)/2;
For (z = 3; z <31; z ++)
{
For (x = 1; x ++)
{
Xz = myPow (x, z );
If (xz> = k/2)
Break;
If (FindIt (x + 1, 13 00 ))
Ans ++;
}
}
Printf ("% d \ n", ans );
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.