6 kyu
Simple Fun #142: Mobius function
100 of 368myjinxin2015
Description:
Task
Compute the Mobius function for a given value of n
.
For a given n
, the Mobius function is equal to:
0
ifn
is divisible by the square of any prime number. For examplen
=4, 8, 9
are all divisible by the square of at least one prime number.1
ifn
is not divisible by the square of any prime numbers, and has an even number of prime factors. For examplen
=6, 10, 21
satisfy these conditions (e.g.21 = 3 * 7
so it has an even number (2) of distinct prime factors and is not divisible by the square of any prime numbers).-1
otherwise. For examplen
=3, 5, 7, 30
.
Input/Output
You will be given an integer n
; you must return an integer - the Mobius function of n
.
Performance requirements:
2 <= n <= 1e12
Puzzles
Similar Kata:
Stats:
Created | Feb 20, 2017 |
Published | Feb 20, 2017 |
Warriors Trained | 1698 |
Total Skips | 74 |
Total Code Submissions | 3088 |
Total Times Completed | 368 |
JavaScript Completions | 100 |
C# Completions | 33 |
Python Completions | 156 |
Ruby Completions | 45 |
C++ Completions | 52 |
Java Completions | 29 |
Total Stars | 39 |
% of votes with a positive feedback rating | 92% of 109 |
Total "Very Satisfied" Votes | 95 |
Total "Somewhat Satisfied" Votes | 10 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 7 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |