# encoding=utf-8 ''' Niu Niu got a positive integer pair (x, y) from the teacher before, Niu Niu forgot how many they were. But Niu Niu remembers that the teacher told him that neither x nor y is greater than n, and the remainder of dividing x by y is greater than or equal to k . Niu Niu wants you to help him calculate how many possible pairs there are. The input consists of two positive integers n,k(1 <= n <= 10^5, 0 <= k <= n - 1) . Output description : For each test case , output a positive integer representing the number of possible pairs. Example 1 Input 5 2 Output 7 Description The number pairs that satisfy the conditions are (2,3),(2,4),(2,5),(3,4),(3,5),(4,5), (5,3) ''' if __name__ == '__main__' : str = raw_input() ls = [int(n) for n in str.split()] n = ls [ 0 ] k = ls [ 1 ] res = 0 for y in range(max(k, 1), n + 1): res += n/y*(y - k) if n % y >= k: if k: res + = n% y - k + 1 else : res += n % and print res
Written test: Niu Niu number pair problem python
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324506825&siteId=291194637
Recommended
Ranking