Number of divisors
Practice
3.9 (93 votes)
Backtracking
Basic programming
Number theory
Recursion
Problem
69% Success 12627 Attempts 30 Points 1s Time Limit 64MB Memory 1024 KB Max Code

You are given two numbers n and k. For each number in the interval [1, n], your task is to calculate its largest divisor that is not divisible by k. Print the sum of these divisors.

Note: k is a prime number.

Input format

  • The first line contains an integer T representing the number of test cases that will follow.
  • Each test case consists of one line containing two integers n and k.

Output format

The output must contain the answer for each test case on a different line.

Each answer consists of a single integer.

Constraints

\(T \le 300000\\ 1 \le n \le 1000000000\\ 2 \le k \le 1000000000\)
 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
10 votes
Tags:
BacktrackingBasic ProgrammingRecursion
Points:30
8 votes
Tags:
Basic ProgrammingRecursionRecursion and BacktrackingC++
Editorial

Login to unlock the editorial