There is a BUG in the refactoring code I provided. This BUG is found inBirds _ AsukaThe netizen pointed out that "is it time-complex?" and said that "at first glance, I wanted to think of it as a mathematical problem, I found out again after thinking about the problem in mathematics.
#include <stdio.h> main( i , sum = ( i = ; i <= ; i +++=
#include <stdio.h> main( , ( + ) * /
). The "Number of rectangles" problem should be said that it is not so easy to obtain mathematical solutions.
Birds _ AsukaAfter the netizen said that he "first saw me and wanted to think of it as a mathematical problem", I also tried to think about it in a mathematical way. I found that n different points on the same line can constitute (n-1) n/2 different line segments, the rectangle of A * B has A + 1 and B + 1 different points on the adjacent sides, so they can form (A + 1) A/2 and (B + 1) respectively) b/two different line segments. In this way, the number of rectangles is (A + 1) A/2 × (B + 1) B/2. When the maximum value of A and B is 1000, the result is obviously not less than 25 × 1010, and this value is obviously greater than 231-1, even greater than 232-1 (the maximum integer that can be expressed by the unsigned type in most compilers ). In this way, the int type is used as the result type in the original refactoring code, which is obviously wrong.
)
Birds _ AsukaSome netizens pointed out that the problem of "time complexity is relatively large" also exists. However, for the convenience of algorithm description, the count () function was not written as follows:
count( A , x1 , y1 ; x2 , y2 ; num = ( x1 = ; x1 < B ; x1 ++ ) ( y1 = ; y1 < A ; y1 ++ ) ( x2 = x1 + ; x2 <= B ; x2 ++ ) ( y2 = y1 + ; y2 <= A ; y2 ++ ) num ++ ;
( x1 = ; x1 < B ; x1 ++ ( x2 = x1 + ; x2 <= B ; x2 ++ ( y1 = ; y1 < A ; y1 ++ ( y2 = y1 + ; y2 <= A ; y2 ++++ ;
typedef BIG_NUM[] ;
count( BIG_NUM m , A , ] = ] = mul_sum( m , B );}
mul_sum( BIG_NUM m , t1 = n % == ? n / = n % != ? (n + ) / : n +
mul( BIG_NUM m , ] *=] *=] += m[]/; m[] %=
( m[] == , m[ , m[ , m[
<stdio.h>typedef BIG_NUM[ count( BIG_NUM , , mul_sum( BIG_NUM , mul( BIG_NUM , POW 1000000 WID 6 main( ( printf( , &A , &B )!= ( m[] == , m[ , m[ , WID , m[ mul( BIG_NUM m , ] *=] *=] += m[]/POW; m[] %= count( BIG_NUM m , A , ] = ] = mul_sum( m , B ); mul_sum( BIG_NUM m , t1 = n % == ? n / = n % != ? (n + ) / : n +