原题链接: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. JDK8 metaspace调优

    从JDK8开始,永久代(PermGen)的概念被废弃掉了,取而代之的是一个称为Metaspace的存储空间.Metaspace使用的是本地内存,而不是堆内存,也就是说在默认情况下Metaspace的大 ...

  2. 模块-Memcached、Redis

    目录 Mecache 安装 使用 Redis 安装 Python操作Redis 操作模式 连接池 操作 String Hash List Set sort set 其他常用操作 管道 发布订阅 sen ...

  3. linux, configure --prefix 的作用

    指定安装路径不指定prefix,则可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc.其它的资源文件放在/usr ...

  4. Spring笔记②--各种属性注入

    Ioc 反转控制 反转资源获取的方向 分离接口与实现 采用工厂模式 采用反转控制   Di 依赖注入 依赖容器把资源注入   配置bean 通过全类名(反射) 配置形式:基于xml方式 Ioc容器的b ...

  5. 阅读<构建之法>第三10、11、12章并提出问题

    <构建之法>第10.11.12章 第10章: 问题:对我们了解了用户的需求后,但是我们想法和做出来的软件会和用户的需求有偏差,比如风格.界面的修饰等等,那么我们程序猿怎样才能让自己的想法更 ...

  6. Gradle入门(4):依赖管理

    在现实生活中,要创造一个没有任何外部依赖的应用程序并非不可能,但也是极具挑战的.这也是为什么依赖管理对于每个软件项目都是至关重要的一部分. 这篇教程主要讲述如何使用Gradle管理我们项目的依赖,我们 ...

  7. 笔记:EF出现列名 'Discriminator' 无效、类没有加入数据库上下文也被数据迁移生成表

    笔记: EF出现列名 'Discriminator' 无效: 类没有加入数据库上下文也被数据迁移生成表: 出现该问题一般是使用了某个基类继承了实体类: 原因是code first的POCO实体对象的继 ...

  8. 【高级】PHP-FPM和Nginx的通信机制

    PHP-FPM 介绍 CGI 协议与 FastCGI 协议 每种动态语言( PHP,Python 等)的代码文件需要通过对应的解析器才能被服务器识别,而 CGI 协议就是用来使解释器与服务器可以互相通 ...

  9. 一个Flume 异常(Put queue for MemoryTransaction of capacity 100 full)的排查和解决思路

    最近在做一个分布式调用链跟踪系统, 在两个地方采用了flume (我使用的flume版本是1.5.0-cdh5.4.4),一个是宿主系统 ,用flume agent进行日志搜集. 一个是从kafka拉 ...

  10. Boa服务器移植

    Boa是一种非常小巧的Web服务器,其可执行代码只有大约60KB左右.作为一种单任务Web服务器,Boa只能依次完成用户的请求,而不会fork出新的进程来处理并发连接请求.但Boa支持CGI,能够为C ...