UVa 10179 - Irreducable Basic Fractions
题目大意:给一个正整数n,求出在[1, n]区间内和n互质的正整数的个数。Euler's Totient(欧拉函数)的直接应用。
#include <cstdio>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
#define MAXN 10000000 bitset<MAXN+> bs;
vi primes; void sieve(ll upper)
{
bs.set();
bs.set(, false);
bs.set(, false);
for (ll i = ; i <= upper; i++)
{
if (bs.test((size_t)i))
for (ll j = i*i; j <= upper; j++)
bs.set((size_t)j, false);
primes.push_back((int)i);
}
} vi primeFactors(ll n)
{
vi factors;
int idx = , pf = primes[idx];
while (n != && (pf*pf <= n))
{
while (n % pf == )
{
n /= pf;
factors.push_back(pf);
}
pf = primes[++idx];
}
if (n != ) factors.push_back(n);
return factors;
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
sieve(MAXN);
int n;
while (scanf("%d", &n) && n)
{
vi factors = primeFactors(n);
vi::iterator last = unique(factors.begin(), factors.end());
int result = n;
for (vi::iterator it = factors.begin(); it != last; it++)
result = result - result/(*it);
printf("%d\n", result);
}
return ;
}
UVa 10179 - Irreducable Basic Fractions的更多相关文章
- 【Uva 12558】 Egyptian Fractions (HARD version) (迭代加深搜,IDA*)
IDA* 就是iterative deepening(迭代深搜)+A*(启发式搜索) 启发式搜索就是设计估价函数进行的搜索(可以减很多枝哦~) 这题... 理论上可以回溯,但是解答树非常恐怖,深度没有 ...
- UVa 10299 - Relatives
题目大意:Euler's Totient的应用. 几乎和UVa 10179 - Irreducable Basic Fractions一样,于是偷了个懒,直接用10179题的代码,结果WA了,感觉一样 ...
- 2021.08.10 Euler函数总结
2021.08.10 Euler函数总结 知识: 记 φ(n) 表示在 [1,n] 中与 n互质的数的个数. 1.p为质数,则 \[φ(p^l)=p^l-p=p^{l-1}(p-1) \] 注:每p个 ...
- 暴力枚举 UVA 10976 Fractions Again?!
题目传送门 /* x>=y, 1/x <= 1/y, 因此1/k - 1/y <= 1/y, 即y <= 2*k */ #include <cstdio> #inc ...
- UVA.10986 Fractions Again (经典暴力)
UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...
- uva 10976 Fractions Again(简单枚举)
10976 Fractions Again It is easy to see that for every fraction in the form 1 k (k > 0), we can a ...
- Uva 10976 Fractions Again?!
直接暴力 没技巧 y应该从k+1开始循环,因为不然y-k<0的时候 你相当于(x*y) % (负数) 了. #include <iostream> using namespace s ...
- uva 10976 fractions again(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB3gAAAM+CAIAAAB31EfqAAAgAElEQVR4nOzdO7KtPJum69GEpAcVQQ ...
- UVa 12558 - Egyptian Fractions (HARD version)
题目大意: 给出一个真分数,把它分解成最少的埃及分数的和.同时给出了k个数,不能作为分母出现,要求解的最小的分数的分母尽量大. 分析: 迭代加深搜索,求埃及分数的基础上,加上禁用限制就可以了.具体可以 ...
随机推荐
- Python科学计算学习一 NumPy 快速处理数据
1 创建数组 (1) array(boject, dtype=None, copy=True, order=None, subok=False, ndmin=0) a = array([1, 2, 3 ...
- ubuntu server 12.04 源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 deb http://mirrors.163.com/ubuntu/ precise ...
- CentOS 系统中安装postfix+dovecot+openwebmail <转>
一.先卸载sendmain[root@ser ~]# yum remove sendmail 二.安装postfix ,dovecot,cyrus-sasl[root@ser ~]# yum -y ...
- 几种在shell命令行中过滤adb logcat输出的方法
我们在Android开发中总能看到程序的log日志内容充满了屏幕,而真正对开发者有意义的信息被淹没在洪流之中,让开发者无所适从,严重影响开发效率.本文就具体介绍几种在shell命令行中过滤adblog ...
- Swaps in Permutation
Swaps in Permutation You are given a permutation of the numbers 1, 2, ..., n and m pairs of position ...
- Android----paint触摸轨迹监听
paint触摸轨迹监听,主要是三种而已,ACTION_DOWN,ACTION_MOVE,ACTION_UP public boolean onTouchEvent(MotionEvent event) ...
- adb not responding. if you'd like to
在安装genymotion后启动工程报此错误. 解决方案:把其他虚拟机删掉,然后用genymotion新建一个,启动工程OK.
- Chapter 1 First Sight——1
My mother drove me to the airport with the windows rolled down. 随着窗户渐渐摇下,我妈妈开着车送我去机场. It was seventy ...
- dashboard项目心得:
DAO类实现查找数据并放入一个map public Map<String,Integer> getAllBlock_multi(String projectname){ LinkedHas ...
- unittest单元测试框架总结
unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...