The Holmes children are fighting over who amongst them is the cleverest.
Mycroft asked Sherlock and Eurus to find value of f(n), where f(1) = 1 and for n ≥ 2, f(n) is the number of distinct ordered positive integer pairs (x, y) that satisfy x + y = n and gcd(x, y) = 1. The integer gcd(a, b) is the greatest common divisor of a and b.
Sherlock said that solving this was child's play and asked Mycroft to instead get the value of . Summation is done over all positive integers d that divide n.
Eurus was quietly observing all this and finally came up with her problem to astonish both Sherlock and Mycroft.
She defined a k-composite function Fk(n) recursively as follows:
![](http://codeforces.com/predownloaded/4e/27/4e27d9702ba6c47f91fbb6553f9ae99f24da520a.png)
She wants them to tell the value of Fk(n) modulo 1000000007.
A single line of input contains two space separated integers n (1 ≤ n ≤ 1012) and k (1 ≤ k ≤ 1012) indicating that Eurus asks Sherlock and Mycroft to find the value of Fk(n) modulo 1000000007.
Output a single integer — the value of Fk(n) modulo 1000000007.
7 1
6
10 2
4
In the first case, there are 6 distinct ordered pairs (1, 6), (2, 5), (3, 4), (4, 3), (5, 2) and (6, 1) satisfying x + y = 7 and gcd(x, y) = 1. Hence, f(7) = 6. So, F1(7) = f(g(7)) = f(f(7) + f(1)) = f(6 + 1) = f(7) = 6.
一道数论题。欧拉函数真是个神奇的东西。。。
首先,题目的意思即那个公式。f(n)表示对于一对x,y,如果x+y=n,gcd(x,y)=1,那么这对x,y为函数f(n)做了1 的贡献。
那么我们可以试图反推一下:y=n-x,gcd(x,y)=1,gcd(x,n-x)=1,那这个gcd(x,n-x)=1与gcd(x,n)有什么关系吗?答案是 有关系。我们可以假设如果gcd(x,n)=k,那么n=n'k ,x=x'k 那么gcd(x,n-x)=gcd(x'k,(n'-x')k)=k,与之前的gcd(x,n-x)=1矛盾,所以我们发现gcd(x,y)=1和gcd(x,n)=1。那么f(n)函数就可以理解成求n以内,与n互质的数的个数。我们会发现这就是欧拉函数的定义。所以对于f(n),我们只需要求出phi(n)即可。对于g(n),. Summation is done over all positive integers d that divide n. 这句话的意思就是g(n)=n的所有引述的欧拉函数之和。然而我们可以将某个定义记住:n的所有因数的欧拉函数之和等于n。至此,我们已经知道了g(n),f(n),对于这道题我们就可以很轻松的解决了。
只需要求出(k+1)/2次欧拉函数即可,然后判断一下1,即可解决这道题。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#define eps 1e-8
#define zero(x) (((x>0?(x):-(x))-eps)
#define mem(a,b) memset(a,b,sizeof(a))
#define memmax(a) memset(a,0x3f,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define ull unsigned long long
#define sf(a) scanf("%d",&a)
#define sf64(a) scanf("%I64d",&a)
#define sf264(a,b) scanf("%I64d%I64d",&a,&b)
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sff(a) scanf("%f",&a)
#define sfs(a) scanf("%s",a)
#define sfs2(a,b) scanf("%s%s",a,b)
#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)
#define sfd(a) scanf("%lf",&a)
#define sfd2(a,b) scanf("%lf%lf",&a,&b)
#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)
#define sfc(a) scanf("%c",&a)
#define ull unsigned long long
#define pp pair<int,int>
#define debug printf("***\n")
#define pi 3.1415927
#define mod 1000000007
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a, int b){ return a>b; }
bool cmpsmall(int a, int b){ return a<b; }
using namespace std;
ll phi(ll n) //求phi(n)模板
{
ll ret=n;
for(ll i=2;i*i<=n;i++)
if(n%i==0)
{
ret-=ret/i;
while(n%i==0) n/=i;
}
if(n>1)
ret-=ret/n;
return ret;
}
int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out" ,"w",stdout);
ll n,k;
while(~sf264(n,k))
{
k=(k+1)/2;
while(k--&&n>1)
n=phi(n);
printf("%I64d\n",n%1000000007);
}
return 0;
}