6 kyu

Simple Fun #142: Mobius function

100 of 368myjinxin2015

Description:

Task

Compute the Mobius function μ(n)\mu (n) for a given value of n.

For a given n, the Mobius function is equal to:

  • 0 if n is divisible by the square of any prime number. For example n = 4, 8, 9 are all divisible by the square of at least one prime number.

  • 1 if n is not divisible by the square of any prime numbers, and has an even number of prime factors. For example n = 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 example n = 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

Stats:

CreatedFeb 20, 2017
PublishedFeb 20, 2017
Warriors Trained1698
Total Skips74
Total Code Submissions3088
Total Times Completed368
JavaScript Completions100
C# Completions33
Python Completions156
Ruby Completions45
C++ Completions52
Java Completions29
Total Stars39
% of votes with a positive feedback rating92% of 109
Total "Very Satisfied" Votes95
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes4
Total Rank Assessments7
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • monadius Avatar
  • hobovsky Avatar
  • mouloud Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • koba1996 Avatar
  • benjaminzwhite Avatar
Ad