Question link: http://acm.csu.edu.cn/OnlineJudge/problem.php? Id = 1337
Solution Report: although the range of X and Y is 10 ^ 8, if A is greater than 1000, A ^ 3 will be greater than 10 ^ 9, in this way, there is only one 10 * C + 3 on the right of the equal sign, which can only reach 10 ^ 9 orders of magnitude. Therefore, no matter how many X and Y are input, we only need to take the range from 1 to 1000, enumerate a and B, then C can get, and then judge whether the range of C is between x and y, in this way, the time complexity is reduced to 10 ^ 6.
1 # include <cstdio> 2 # include <cstring> 3 # include <iostream> 4 # include <algorithm> 5 # include <cstdlib> 6 using namespace STD; 7 typedef long int; 8 int th [1005]; 9 void dabiao () 10 {11 for (INT I = 1; I <= 1000; ++ I) 12 th [I] = I * I; 13} 14 int main () 15 {16 dabiao (); 17 int X, Y; 18 int Kase = 1; 19 while (scanf ("% LLD", & X, & Y )! = EOF) 20 {21 int ans = 0; 22 int A = min (x, (INT) 1000); // There Is No 23 int B = min (Y, (INT) 1000); 24 for (INT I = A; I <= B; ++ I) 25 for (Int J = A; j <= B; ++ J) 26 {27 int S = th [I] + Th [J]; 28 If (S % 10 = 3 & S/10 <= y) 29 ans ++; 30} 31 printf ("case % d: % LLD \ n", Kase ++, ANS); 32} 33 return 0; 34}
View code
CSU 1337 funny copyright Fei Ma Da's theorem (question J in Hunan Programming Competition 2013)