【codeforces 776E】The Holmes Children
【题目链接】:http://codeforces.com/contest/776/problem/E
【题意】
f(n)是小于n的不同整数对(x,y)这里x+y==n且gcd(x,y)==1的个数;
g(n)是n的所有因子的f值的和;
然后让你求一个递推式
【题解】
x的欧拉函数为phi(x)
则f(n)=phi(n);
欧拉函数的定义是,小于这个值且与这个值互质的数的个数->phi(n);
可以证明每一个与n互质的数x对应了一个整数对(x,y)且x+y==n且gcd(x,y)==1;
然后有个可以记住的东西;
n的所有因子的欧拉函数的和为这个数本身;
所以
f(n)=phi(n);
g(n)=n
根据递推式容易求出fk(n);
做(k+1)/2次欧拉函数就好;
偶数次只是传值;奇数次在计算;
在数论中,对于正整数N,少于或等于N ([1,N]),且与N互质的正整数(包括1)的个数,记作φ(n)。
/*
在数论中,对于正整数N,少于或等于N ([1,N]),且与N互质的正整数(包括1)的个数,记作φ(n)。
φ函数的值:
φ(x)=x(1-1/p(1))(1-1/p(2))(1-1/p(3))(1-1/p(4))…..(1-1/p(n)) 其中p(1),p(2)…p(n)为x
的所有质因数;x是正整数; φ(1)=1(唯一和1互质的数,且小于等于1)。注意:每种质因数只有一个。
例如:
φ(10)=10×(1-1/2)×(1-1/5)=4;
1 3 7 9
φ(30)=30×(1-1/2)×(1-1/3)×(1-1/5)=8;
φ(49)=49×(1-1/7)=42;
*/
【Number Of WA】
1
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;
LL n, k,num;
LL MOD = 1e9 + 7;
LL oula(LL x)
{
LL rest = x;
for (LL i = 2; i*i <= x;i++)
if (x%i == 0)
{
rest -= rest / i;
while (x%i == 0) x /= i;
}
if (x > 1)
rest -= rest / x;
return rest;
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rel(n), rel(k);
num = (k + 1) / 2;
while (num-- && n > 1)
n = oula(n);
cout << n%MOD << endl;
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 776E】The Holmes Children的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【16.23%】【codeforces 586C】Gennady the Dentist
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- 如何直接打开android系统的wifi设置页面,防止intent劫持
在android的app开发中,经常会遇到需要跳转至系统设置页面的需求.但是当你使用以下代码时: 如 Intent intent = new Intent(Settings.ACTION_WIFI_ ...
- 使iframe随内容(target到iframe的内容)改变而自适应高度,完美解决各种获取第一个demo高度后第二个高度不变情况
转自:http://caiceclb.iteye.com/blog/281102 很高兴,终于使用jquery实现了点击外部链接,更改iframe内容时,iframe的高度自适应问题. 失败的测试就不 ...
- 使用psutil模块获取电脑运行信息
psutil是python的一个用于获取cpu信息的模块,非常好使,以下附上官方的一些example: CPU-> Examples >>> import psutil > ...
- Reward(toposort)
http://acm.hdu.edu.cn/showproblem.php?pid=2647 #include <stdio.h> #include <string.h> #i ...
- linux上搭建svn
参照网址:http://www.cnblogs.com/LusYoHo/p/6056377.html(如何在linux下搭建svn服务) http://www.cnblo ...
- Coursera公开课-Machine_learing:编程作业2
第三周编程作业:Logistic Regression 代码包在gitlab上:https://gitlab.com/luntai/Machine_Learning
- 关于BUG
1.BUG的理解 2.提高BUG report的技巧
- 兼容浏览器 div固定浏览器窗口底部 浮动div
css内容: <style type="text/css"> #ken_BB { padding-right:30px; text-align: center; col ...
- 执行update, insert,delete 语句, 不返回结果集,(类型化参数)
/// <summary> /// 执行update, insert,delete 语句, 不返回结果集,(类型化参数) /// </summary> /// <para ...
- javascript部分知识点
1:script放置位置: a:<title></title>之后 b:<body>之后 c:<body>中的<div></div&g ...