POJ2480 Longge's problem gcd&&phi
题意简洁明了。做这题主要是温习一下phi的求法。令gcd(i,n)=k,实际上我们只需要求出有多少个i使得gcd(i,n)=k就可以了,然后就转化成了求phi(n/k)的和,但是n很大,我们不可能预处理出所有的phi,但是因为k的个数是O(sqrt(n))级别的,所以我们只需要求出sqrt(n)个数的phi就可以了,我们先预处理出所有的质因子及其个数,然后dfs一下就可以了。
#pragma warning(disable:4996)
#include<cstring>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std; int n;
int cnt[35];
int prime[35];
int tot;
ll ans; void dfs(int step, int phi)
{
if (step == tot){
ans += (ll)phi; return;
}
dfs(step + 1, phi);
phi = phi / prime[step] * (prime[step] - 1);
for (int i = 0; i < cnt[step]; i++){
dfs(step + 1, phi);
}
} int main()
{
while (~scanf("%d",&n))
{
memset(cnt, 0, sizeof(cnt)); tot = 0;
int x = n;
for (ll i = 2; i*i <= x; i++){
if (x%i == 0){
for (; x%i == 0; x /= i) cnt[tot]++;
prime[tot++] = i;
}
if (x == 1) break;
}
if (x != 1) cnt[tot]++, prime[tot++] = x;
ans = 0;
dfs(0, n);
printf("%lld\n", ans);
}
return 0;
}
POJ2480 Longge's problem gcd&&phi的更多相关文章
- POJ2480 Longge's problem
题意 Language:Default Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1064 ...
- poj2480——Longge's problem(欧拉函数)
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9190 Accepted: 3073 ...
- POJ2480:Longge's problem(欧拉函数的应用)
题目链接:传送门 题目需求: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N ...
- Longge's problem poj2480 欧拉函数,gcd
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6918 Accepted: 2234 ...
- POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6383 Accepted: 2043 ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- Longge's problem
Longge's problem 求\(\sum_{i=1}^ngcd(i,n)\),\(n< 2^{31}\). 解 理解1: 注意式子的实际意义,显然答案只可能在n的约数中,而现在问题变成了 ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- 365. Water and Jug Problem (GCD or BFS) TBC
https://leetcode.com/problems/water-and-jug-problem/description/ -- 365 There are two methods to sol ...
随机推荐
- Oracle静态数据字典
select * from user_tab_comments a where a.comments like '%操作%' 数据字典 寻找数据库中注释带有“操作”二字的所有表 静态数据字典 这类 ...
- db.properties 数据库配置文件
project.pool.initialPoolSize project.pool.minPoolSize project.pool.maxPoolSize project.db.tablePrefi ...
- 记录一下hdu的几道题
杭州电子科技大学程序设计竞赛 2016‘12-网络同步赛 前几天看到这个比赛,想着要是到时候没事就做一下,但是中午实在太困,加上水平太次,才a了4道题目. 说明:我是看ac人数多少的顺序来做题的. 1 ...
- oracle连接和执行流程总结
参考关于oracle连接及一个事务的完整流程分析的资料,做整理如下 参考资料: http://blog.csdn.net/wyzxg/archive/2010/08/16/5815335.aspx h ...
- phpStudy 2016 更新下载,新版支持php7.0
目标:让天下没有难配的php环境. phpStudy Linux版&Win版同步上线 支持Apache/Nginx/Tengine/Lighttpd/IIS7/8/6 『软件简介』该程序包集成 ...
- cookie文件在电脑的保存位置
在Windows系统上(这里以Win7为例)浏览器的Cookie IE浏览器Cookie数据位于:%APPDATA%\Microsoft\Windows\Cookies\ 目录中的xxx.txt文件 ...
- 伴随ListView、RecyclerView、ScrollView滚动滑入滑出小图标--第三方开源--FloatingActionButton
FloatingActionButton在github上的项目主页是:https://github.com/makovkastar/FloatingActionButton 它的依赖包NineOldA ...
- (转)可收缩、扩展的TextView
在一些应用中,比如腾讯的应用市场APP应用宝,关于某款应用的介绍文字,如果介绍文字过长,那么不是全部展现出来,而是显示三四行的开始部分(摘要),预知全部的内容,用户点击展开按钮即可查阅全部内容.这样的 ...
- c#中的类型转换
Parse类型转换 Parse()函数 int.double都能调用Parse()函数,Parse(string str);如果转换成功就成功,失败就会抛出一个异常; TryParse()函数 相应地 ...
- Android 中的WiFi剖析
Android的WiFi 我们通常看到WiFi的守护进程wpa_supplicant在我们的ps的进程列表中,这个就是我们的wifi守护进程.wpa_supplicant在external/wpa_s ...