Mutiple

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5211

Description

wld有一个序列a[1..n], 对于每个1≤i<n, 他希望你求出一个最小的j(以后用记号F(i)表示),满足i<j≤n, 使aj为ai的倍数(即aj mod ai=0),若不存在这样的j,那么此时令F(i) = 0
保证1≤n≤10000,1≤ai≤10000 对于任意 1≤i≤n, 且对于任意1≤i,j≤n(i!=j),满足ai != aj

Input

多组数据(最多100组)
对于每组数据:
第一行:一个数n表示数的个数
接下来一行:n个数,依次为a1,a2,…,an
接下来一行:一个数k表示操作数

Output

对于每组数据:
输出最多剩下的不同的数的个数

Sample Input

4
1 3 1 2

Sample Output

6

HINT

F(1)=2
F(2)=0
F(3)=4
F(4)=0

题意

题解:

对于每一个数,我们都直接枚举倍数就好了,直接倒着做!

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
} int a[],mp[]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
ll ans=;
for(int i=;i<=n;i++)
a[i]=read();
for(int i=;i<=;i++)
mp[i]=n+;
for(int i=n;i;i--)
{
int mi=n+;
for(int j=a[i];j<;j+=a[i])
mi=min(mi,mp[j]);
if(mi<=n)
ans+=mi;
mp[a[i]]=i;
}
printf("%lld\n",ans);
}
}

hdu 5211 Mutiple 数学的更多相关文章

  1. hdu.5211.Mutiple(数学推导 && 在logn的时间内求一个数的所有因子)

    Mutiple  Accepts: 476  Submissions: 1025  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 6553 ...

  2. HDU 5211 Mutiple 水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5211 题解: 1.筛法: #include<iostream> #include< ...

  3. HDU 5673 Robot 数学

    Robot 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 Description There is a robot on the origi ...

  4. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  5. HDU 2493 Timer 数学(二分+积分)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493 题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来 ...

  6. HDU 1568 Fibonacci 数学= = 开篇

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1568 分析:一道数学题 找出斐波那契数列的通项公式,再利用对数的性质就可得到前几位的数 斐波那契通项公 ...

  7. hdu 4602 Partition 数学(组合-隔板法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602 我们可以特判出n<= k的情况. 对于1<= k<n,我们可以等效为n个点排成 ...

  8. HDU 1030 Delta-wave 数学题解

    给出一个数字塔,然后求沿着数字之间的边走,给出两个数字,问其路径最短的长度是多少. 看似一条搜索题目,只是有一定做题经验的人都知道,这个不是搜索题,直接搜索肯定超时. 这个是依据规律计算的数学题目. ...

  9. HDU 5698 瞬间移动 数学

    瞬间移动 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5698 Description 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次 ...

随机推荐

  1. CentOS中搭建Redis伪分布式集群【转】

    解压redis 先到官网https://redis.io/下载redis安装包,然后在CentOS操作系统中解压该安装包: tar -zxvf redis-3.2.9.tar.gz 编译redis c ...

  2. MySQL-索引工作原理及使用注意事项

    1.为什么需要索引(Why is it needed)? 当数据保存在磁盘类存储介质上时,它是作为数据块存放.这些数据块是被当作一个整体来访问的,这样可以保证操作的原子性.硬盘数据块存储结构类似于链表 ...

  3. C++——stoi函数

    版权声明:本文系原创,转载请声明出处. 1. 函数原型 , ); , ); 2. 参数说明 str String object with the representation of an integr ...

  4. CRM 业务

    1. 创建CRM项目 引入插件 创建数据库 from django.db import models from django.db import models class Department(mod ...

  5. Ceph 时钟偏移问题 clock skew detected 解决方案--- 部署内网NTP服务

    告警:HEALTH_WARN clock skew detected on mon.ip-10-25-195-6; 8 requests are blocked > 32 sec; Monito ...

  6. poj 1041(字典序输出欧拉回路)

    John's trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8641   Accepted: 2893   Spe ...

  7. git - git命令中文显示乱码

    使用git add添加要提交的文件的时候,如果文件名是中文,会显示形如897\232\350\256...的乱码,解决办法:   git config --global core.quotepath ...

  8. 常用对称加密算法(DES/AES)类(PHP)

    看注释,啥也不说了,欢迎各种跨平台测试! /** * 常用对称加密算法类 * 支持密钥:64/128/256 bit(字节长度8/16/32) * 支持算法:DES/AES(根据密钥长度自动匹配使用: ...

  9. yii2 DateTimePicker显示到天

    扩展是 kartik\datetime\DateTimePicker; 关键是加入此配置  'minView'=> "month",示例如下: <?php echo D ...

  10. Python爬虫-urllib的基本用法

    from urllib import response,request,parse,error from http import cookiejar if __name__ == '__main__' ...