已知正整数 n,k,求满足 n>=x>=1,n>=y>=1,x%y>=k 的所有(x,y)组合

时间:2020-12-18 15:14:19
import java.util.Scanner;
/**
 * 已知正整数 n,k,求满足 1<=x<=n,1<=y<=n,x%y>=k 的所有(x,y)组合
 * 输入:
 * 5 2
 * 解释:
 * n=5,k=2
 * (2,3),(2,4),(2,5),(3,4),(3,5),(4,5),(5,3)
 * 输出:
 * 7
 */

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int count =0;
for(int i=k+1;i<=n;i++){
count += (n/i)*(i-k);
if(n%i-k+1>0) count += n%i-k+1;
}
System.out.println(count);
sc.close();
}
}