phi-phi-phi

3.5

15 votes
Easy, Euler's totient function, Math, Number Theory
Problem

Given n and k, calculate φ(φ(...φ(n)...)), where φ applied exactly k times.

φ(n) is Euler's totient function. φ(1)=1 by definition.

You can find the definition of Euler's totient function here.

Input format

The only line of input contains two integers n and k (1n1018, 1k1018).

Output format

Print one integer - answer to the problem.

Scoring

n103, k103 - 10 points

n106, k1018 - 15 points

n1012, k=1 - 10 points

n1012, k1018 - 10 points

n1015, k=1 - 5 points

n1015, k1018 - 40 points

n1018, k1018 - 10 points

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

φ(12)=4 and φ(4)=2

So the answer is 2.

Editor Image

?