CSU 1337
Time Limit:1000MS
Memory Limit:131072KB
64bit IO Format:%LLD &%llu
Description
Flt theorem: When n>2, the indefinite equation AN+BN=CN has no positive integer solution. For example, A3+B3=C3 does not have a positive integer solution. To enliven the atmosphere, we might as well have a funny version: Change the equation to a3+b3=c3, so there are solutions, such as a=4, B=9, c=79 43+93=793.
Enter two integers x, y, to satisfy the x<=a,b,c<=y number of integer solutions.
Input
Enter up to 10 sets of data. Each set of data contains two integers x, y (1<=x,y<=108).
Output
For each set of data, the number of output solutions.
Sample Input
Sample Output
Solution : Look at other people's problem solving, found in fact is a very good question, at first did not understand the meaning of the deep layer of the topicin fact, although the range of x and Y is 10^8, but if a is greater than 1000, then the a^3 will be greater than 10^9, so that the right side of the equal sign is only one x C + 3, the largest can only reach the 10^9 order of magnitude, so, regardless of the input of the number of Xs and y, We just have to take the interval between 1 and 1000, enumerate A and B, then C can get, and then determine whether the range of C is between x and Y, so that the time complexity drops to 10^6,direct violence, two loops are done.
#include<iostream>UsingNamespace Std;IntMain(){int aBCXYM=0N;While(CIN>>x>>y&&x&&y)Y=0;For(A=x; a<=1000&&a<=y; a++)For(b=x; b<=1000&&b<=y; b++){int s=a*a*a+b*b*b;If(s%10!=3)Continue=s/10if (C>=x &&c<=y) n++; }++m<< "case" <<m<< <<n<<endl }return 0;< Span class= "Sh-cbracket" >
CSU 1337 (flt theorem)