How many new friends John has?
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description:
John is the president of the smart code Association. Christmas is coming, he is going to have a party for all the members. All members numbered from 1 to n
(n
is the number of John). Some members are John's old friends, but also some new friends. John found that all his old friend's number and his own number have at least one common divisor (greater than 1
). Please calculate how many new friends John has?
Complete function countNewFriends
. Function accept a argument n
(a positive integer, 0 < n < 30000
). Returns a number that is the total number of John's new friends.
Some Examples
# Counts the number of integers from 1 to n-1 that are coprime with n
# Examples:
# n = 1 -> 0 (No new friends)
# n = 8 -> 3 (New friends: 3, 5, 7)
# n = 9 -> 5 (New friends: 2, 4, 5, 7, 8)
# n = 10 -> 3 (New friends: 3, 7, 9)
# n = 25608 -> 7679 (Large number of friends)
# n = 24027 -> 16015 (Large number of friends)
Note:
- You can assume that all inputs are valid.
- The friend which number is 1 is always a old friend of John or it's John himself(when n = 1).
A bit difficulty, A bit of fun, happy coding ;-)
Similar Kata:
Stats:
Created | Nov 21, 2016 |
Published | Nov 21, 2016 |
Warriors Trained | 315 |
Total Skips | 38 |
Total Code Submissions | 256 |
Total Times Completed | 110 |
JavaScript Completions | 96 |
Python Completions | 17 |
Total Stars | 14 |
% of votes with a positive feedback rating | 93% of 27 |
Total "Very Satisfied" Votes | 24 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |