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 ...
随机推荐
- mybatis 聚合查询
<resultMap id="ExtResultMap" type="com.demo.partner.po.PartnerPO"> <id ...
- 使用HttpWebRequest以及HttpWebResponse读取Http远程文件
主页>杂项技术>.NET(C#)> 使用HttpWebRequest以及HttpWebResponse读取Http远程文件 jackyhwei 发布于 2010-08-15 21: ...
- 【个人】IIS Express 配置
<!-- 查看URL访问控制列表: netsh http show urlacl 添加URL访问控制: netsh http add urlacl url=http://myhostname:8 ...
- Gulp vs Grunt 前端构建工具对比
Gulp vs Grunt 前端工程的构建工具对比 1. Grunt -> Gulp 早些年提到构建工具,难免会让人联想到历史比较悠久的Make,Ant,以及后来为了更方便的构建结构类似的Jav ...
- 安装node和grunt
由于我用的恶事win8的系统,所以在安装nodeJS的时候出现了2503和2502的错误.解决方案: 进入cmd,然后输入msiexec /package [路径:为你将要安装的node所在的位置] ...
- 本地安装gem install --local redis-stat-0.4.13.gem
因为主机环境不能联外网,悲哀,所以只能想办法下载包,上传到主机来安装 环境:el6.x86_64 1. gem 安装[http://centos.ustc.edu.cn/centos/6/os/x86 ...
- JAVA多线程学习--生产者消费者问题
一.问题描述 生产者消费者问题是一个典型的线程同步问题.生产者生产商品放到容器中,容器有一定的容量(只能顺序放,先放后拿),消费者消费商品,当容器满了后,生产者等待,当容器为空时,消费者等待.当生产者 ...
- HTML:form表单总结,input,select,option,textarea,label
<form>标签是块级元素. form标签的标准属性有id,class,style,title,lang,xml:lang. 表单能够包含input元素(包含button,checkbox ...
- selenium for python 所有方法
先列出selenium所有方法,然后挨个使用!说明 add_cookieapplication_cachebackcapabilitiesclosecommand_executorcreate_web ...
- oracle 子查询因子化 浅谈(with的使用)
近来学习oracle,想要提高自己所写语句的效率和易读性,今天的笔记是关于子查询因子话这么一个东西 因子化的查询不一定可以提高效率,但是一定可以再提高程序的可读性方面成效显著 --with 语句 wi ...