Codeforces 776E 数论

本文探讨了Eurus提出的复合函数Fk(n)的问题,这是一个递归定义的函数,涉及欧拉函数φ(n)的计算。文章提供了一个有效求解Fk(n) mod 1000000007的算法实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Holmes Children
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ≥ 2f(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:

She wants them to tell the value of Fk(n) modulo 1000000007.

Input

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

Output a single integer — the value of Fk(n) modulo 1000000007.

Examples
input
7 1
output
6
input
10 2
output
4
Note

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 andgcd(x, y) = 1. Hence, f(7) = 6. So, F1(7) = f(g(7)) = f(f(7) + f(1)) = f(6 + 1) = f(7) = 6.



题意:求fk(n)%1000000007。


题解:

f(n)为欧拉函数

g(n)恒等于n

推荐看下大牛的证明QAQ

因为每走两步n都会取一次phi,所以可以直接暴力。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll phi(ll n){  
    ll ans=n,i;  
    for(i=2;i*i<=n;i++){  
        if(n%i==0){  
            ans=ans-ans/i;  
            while(n%i==0)n/=i;  
        }  
    }  
    if(n>1)ans=ans-ans/n;  
    return ans;  
}  
int main(){
	ll n,k;
	cin>>n>>k;
	while(k>0&&n>1){
		if(k%2==1)n=phi(n);
		k--;
	}
	cout<<n%1000000007<<endl;
	return 0;
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值