原题链接:http://acm.uestc.edu.cn/problem.php?pid=1141

分析:运用欧拉函数可解此题。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <vector>
#define LL long long
using namespace std;
int T;
int n;
int gcd(int a,int b)
{
if(b==)return a;
else return gcd(b,a%b);
}
int dp[];
int phi[];
int get(int n)
{
int rea=n;
for(int i=;i*i<=n;i++)
if(n%i==)
{
rea=rea-rea/i;
do
n/=i;
while(n%i==);
}
if(n>)rea=rea-rea/n;
return rea;
}
void init()
{
for(int i=;i<=;i++)
phi[i]=get(i);
dp[]=;
dp[]=;
dp[]=;
for(int i=;i<=;i++)
{
for(int j=;j<i;j++)
dp[i]=dp[i-]+phi[i]*;
}
}
int main()
{
scanf("%d",&T);
init();
while(T--)
{
scanf("%d",&n);
printf("%d\n",dp[n]);
}
return ;
}

CDOJ--1141的更多相关文章

  1. cdoj 1141 酱神寻宝 状压dp

    酱神寻宝 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1141 Descri ...

  2. poj 1141 Brackets Sequence (区间dp)

    题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cst ...

  3. cdoj 1489 老司机采花

    地址:http://acm.uestc.edu.cn/#/problem/show/1489 题目: 老司机采花 Time Limit: 3000/1000MS (Java/Others)     M ...

  4. POJ #1141 - Brackets Sequence - TODO: POJ website issue

    A bottom-up DP. To be honest, it is not easy to relate DP to this problem. Maybe, all "most&quo ...

  5. 1141. RSA Attack(RSA)

    1141 越来越喜欢数论了 很有意思 先看个RSA的介绍 RSA算法是一种非对称密码算法,所谓非对称,就是指该算法需要一对密钥,使用其中一个加密,则需要用另一个才能解密. RSA的算法涉及三个参数,n ...

  6. poj 1141 Brackets Sequence(区间DP)

    题目:http://poj.org/problem?id=1141 转载:http://blog.csdn.net/lijiecsu/article/details/7589877 定义合法的括号序列 ...

  7. URAL 1141. RSA Attack RSA加密演算法

    标题来源:URAL 1141. RSA Attack 意甲冠军:给你e n c 并有m^e = c(mod n) 求 m 思路:首先学习RSA算法 here 过程大致是 1.发送的信息是m 2.随机选 ...

  8. ****ural 1141. RSA Attack(RSA加密,扩展欧几里得算法)

    1141. RSA Attack Time limit: 1.0 secondMemory limit: 64 MB The RSA problem is the following: given a ...

  9. POJ 1141 Brackets Sequence(括号匹配二)

    题目链接:http://poj.org/problem?id=1141 题目大意:给你一串字符串,让你补全括号,要求补得括号最少,并输出补全后的结果. 解题思路: 开始想的是利用相邻子区间,即dp[i ...

  10. 1141 PAT Ranking of Institutions[难]

    1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...

随机推荐

  1. Binary Tree的3种非Recursive遍历

    Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' valu ...

  2. node上的__dirname和./的区别

    概要 Node.js 中,__dirname 总是指向被执行 js 文件的绝对路径,所以当你在 /d1/d2/myscript.js 文件中写了 __dirname, 它的值就是 /d1/d2 . 相 ...

  3. Rotation and Transform

    A transformation matrix describes the rotation of a coordinate system while an object remains fixed. ...

  4. PAT 1001 A+B Fotmat

    源码 1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calcula ...

  5. "1001. A+B Format (20)" 解题报告

    Github : git@github.com:Circlecos/object-oriented.git PDF Of Markdown : "1001. A+B Format (20)& ...

  6. APP案例分析——Steam

    本次作业的分析对象是Steam,一款全球最大最广泛的游戏平台.之所以选择Steam是因为我已经在这上面挥洒了大量的青春,对它也有了很深的感情. 调研.评测 个人第一次上手体验 打开首页就可以看到琳琅满 ...

  7. iOS 怎么自定制推送声音呢?(APP运行时和APP进入后台时)

    说明: 一般如果修改了apple官方的推送声音后,则APP进入后台后,推送会播放开发者自定制的推送声音,而用户在使用APP(也就是APP运行时)的时候,一般是不会有推送声音,因为此时的推送内容已经呈现 ...

  8. testng对执行失败的用例,再次执行

    前段时间在网络上看到通过重写TestNG的接口,可以再次执行失败的测试用例,于是学习了,我之前的做法是当自己的脚本中碰到异常,就自动调用方法本身来达到再次执行用例的目的,这个过程中有设定重试的次数 对 ...

  9. Mysql高并发情况下的解决方案(转)

    查询了下Mysql 关于高并发的处理的资料,在这记录一下. 高并发大多的瓶颈在后台数据逻辑处理,在存储,mysql的正常的优化方案如下: 1.代码中sql语句优化 2.数据库字段优化,索引优化 3.加 ...

  10. [华三] IPv6技术白皮书(V1.00)

    IPv6技术白皮书(V1.00) http://www.h3c.com/cn/d_200802/605649_30003_0.htm H3C S7500E IPv6技术白皮书 关键词:IPv6,隧道 ...