Code interpretation of programming problems

pairs of positive integers (xpeny), the remainder of xrecery y is greater than or equal to k, the input is nmemery k, and the output is how many, for example, input 52, output 7, logarithms are (2magin3) (2magin4) (2mem5) (3pyrr5) (4preline 5) (5pc5), the code is as follows:

, the logarithm is (2pr 3) (2jue 4) (2je 5) (3je 4) (4pr 5) (5pr 3).

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {        
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        System.out.println(searchCount(n, k));
    }
    public static int searchCount(int n, int k) {
        int count = 0;  //
        int temp;

        //:yx

        for (int y = k + 1; y <= n; yPP) {    //  x%y>=k,y>k
            // n = a*y +b;yy-ky>=k

            count += n/y*(y-k);    

            temp = n%y;
            if(temp >= k) {                    //b>=k
                count += temp-k+1;
            }
        }        
        return count;
    }
}

Why can we infer the explanation y > k if x% y > = k? Why can we find the final number by combining the sentences count + = nUniverse * (ymurk) and count + = temp-k+1?

Feb.27,2021

x% y > = k means that the remainder of x divided by y is greater than or equal to k, and the remainder must be less than y, so y must be greater than k.

count + = nUnix y* (ymerk) means the comment:

suppose n = aqy + b; there are only (ymurk) numerical modules y remainder > = k
in each interval of length y.

count + = temp-k+1; is to calculate how many pairs of b in n = axiy + b satisfy the condition.

for example, nasty 18j karm3.

first of all, y must be greater than 3, because the remainder of the divisor within 3 cannot be greater than or equal to 3. So the for loop starts with knot 1 .

for any y, such as 7, first write Num18 in the form 18 = 2 * 7 + 4 , that is, divide the integers in the range of 1x 18 into 1x 7, 8x 14, and 15x 18. There are y-k=4 in each of the first two paragraphs to meet the requirement that the remainder is greater than or equal to 3. In the last paragraph, only the number of b-k+1=2 is satisfied, that is, 17, 18 .

I suggest you draw it on the axis and you should be able to understand it.


1.X%y result is the remainder of X divided by Y, the remainder < = divisor, and the remainder > k, then y must be > k
2.count + = nmax y (ymerk) is equivalent to count = count + nadir y (YMuk)
3. It's the same as 2

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bd5dfe-30fb5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bd5dfe-30fb5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?