UVa 10299 - Relatives
题目大意:Euler's Totient的应用。
几乎和UVa 10179 - Irreducable Basic Fractions一样,于是偷了个懒,直接用10179题的代码,结果WA了,感觉一样啊...然后就搜,看到n=1的特殊情况,好吧,读题的时候也小小注意了一下"less than" 呢,写代码时就忘的一干二净了...读题时应该把注意事项记下来的...
#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)
{
if (n == )
{
printf("0\n");
continue;
}
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 10299 - Relatives的更多相关文章
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
随机推荐
- JavaScript算法与数据结构知识点记录
JavaScript算法与数据结构知识点记录 zhanweifu
- L7,too late
words: parcel,包裹 detective,侦探 expect,期待 airfield,飞机起落的场地 guard,警戒,守卫,n precious,adj,珍贵的 stone,石头 exp ...
- Day05_JAVAEE系列:Junit
Junit 单元测试开发工具:myeclipse10 内部集成的junit的库 1)什么是junit? junit是一个专业的编写测试代码的工具 2)建立junit测试类的步骤: 2. ...
- Codeforces Round #363 (Div. 2)D. Fix a Tree(并查集)
D. Fix a Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Linux通过防火墙禁止IP来防止攻击
1. iptables -I INPUT -s 211.1.0.0 -j DROP 禁止211.1.0.0这个IP访问服务器 2. iptables -I INPUT -s 211.1.0.0 -j ...
- 处理Easyui的Datagrid无法及时刷新问题
在Easyui中打打开窗口dialog控件,当做完修改操作之后,关闭dialog控件刷新Datagrid,有时候无法及时刷新. 1.JavaScript中的代码 function doEdit(){ ...
- createSQLQuery的addEntity跟setResultTransformer方法
createSQLQuery的addEntity和setResultTransformer方法 1. 使用SQLQuery对原生SQL查询执行的控制是通过SQLQuery接口进行的,通过执行Sessi ...
- Smarty模版
smarty.inc.php <?php //创建一个实际路径 define('ROOT_PATH',dirname(__FILE__)); //引入Smarty require ROOT_PA ...
- vc6 pbo 文件为空的解决方法
使用Profile调试vc6应用程序的性能时,将生成pbo文件,今天在vc IDE中增加了命令行启动参数,导致profile无法生成pbo文件,进而无法生成性能报告. 解决方法: 去掉IDE中的命令行 ...
- editplus 常用
个人习惯风格基本设置:document >preferences >fonts|( Comic sans MS blod 18) -------------------- \n 去换行 ...