CSU 1337 funny copyright Fei Ma Da's theorem (question J in Hunan Programming Competition 2013)

Source: Internet
Author: User

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)

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.