X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Mathematical manipulation
Medium Accuracy: 57.36% Submissions: 466 Points: 4

Given a number n, find the total numbers, less than or equal to n which have at-least one common factor with n other than 1.

Example 1:

Input: n = 6
Output: 4
Explanation: For n=6, the 4 numbers having
a common factor between them and 6
are : 2, 3, 4 & 6


Example 2:

Input: n = 15
Output: 7
Explanation: For N=15, the 7 numbers having a
common factor between them and 15
are : 3, 5, 6, 9, 10, 12, 15


You don't need to read or print anything. Your task is to complete the function CommonFactor() which takes n as input parameter and returns total numbers. less than or equal to n which have atleast one common factor with n other than 1.

Expected Time Complexity: O(nlog(n))
Expected Space Complexity: O(n)

Constraints:
1 <= n <= 105

We are replacing the old Disqus forum with the new Discussions section given below.