原题链接: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. windows docker 安装cloudera/quickstart

    最近需要写一个大数据的项目,但是公司没有测试环境,真是cao蛋,没办法,只能自己搭建一个测试环境,所以就在本地电脑装一个cloudera/quickstart,这个是一个单节点的大数据平台, 是clo ...

  2. join命令详解

    基础命令学习目录首页 原文链接:https://www.cnblogs.com/agilework/archive/2012/04/18/2454877.html 功能说明:将两个文件中,指定栏位内容 ...

  3. nohup命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/hfismyangel/article/details/80258126 1.nohup 用途:不挂断地运行命令. 语法:n ...

  4. cobbler部署以及使用

    常用软件安装及使用目录 资源链接:https://pan.baidu.com/s/1yfVnuSgY5vOTh-B74tpVyw   网盘分享的文件在此 cobbler第一次操作history. ec ...

  5. react-native 常规操作

    1.  关闭xcode打开模拟器的快捷键 , 等常规操作 https://www.jianshu.com/p/f6723f3406b7

  6. 深入理解Java类加载器(ClassLoader) (转)

    转自: http://blog.csdn.net/javazejian/article/details/73413292 关联文章: 深入理解Java类型信息(Class对象)与反射机制 深入理解Ja ...

  7. Teamwork#3,Week5,Scrum Meeting 11.20

    到目前为止,第一轮迭代已经基本完成.由于时间问题,多店比较的高级功能要放到第二轮迭代实现. 大部分任务已经完成,在alpha版本发布之前我们剩余需要解决的问题有两个: 服务器.校园网服务器不能满足我们 ...

  8. 20172319 2018.04.01-04.11 《Java程序设计》第5周学习总结

    20172319 2018.04.01-04.11 <Java程序设计>第5周学习总结 目录 教材学习内容总结 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周考试错 ...

  9. python接口测试之requests库(一)

    一.requests库的安装 requests库作为第三方库,需要安装 cmd模式下,运行pip install requests 二.在学习如何发送请求之前,我们先来了解一下requests库,查看 ...

  10. GC 年轻代 老年代 持久代

    转载自:http://www.cnblogs.com/yaoyuan23/p/5587548.html 虚拟机中的共划分为三个代:年轻代(Young Generation).老年代(Old Gener ...