题目传送门

 /*
设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id,
若没有,默认加0,nlogn复杂度;
我用暴力竟然水过去了:)
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN], b[MAXN]; int main(void) //BestCoder Round #39 1002 Mutiple
{
//freopen ("1002.in", "r", stdin); int n; while (scanf ("%d", &n) == )
{
memset (b, , sizeof (b));
for (int i=; i<=n; ++i) scanf ("%d", &a[i]); long long ans = ;
for (int i=n; i>=; --i)
{
ans += b[a[i]];
for (int j=; j*j<=a[i]; ++j)
{
if (a[i] % j == )
{
b[j] = i; b[a[i]/j] = i;
}
}
} printf ("%lld\n", ans);
} return ;
}

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN]; int main(void) //BestCoder Round #39 1002 Mutiple
{
//freopen ("1002.in", "r", stdin); int n;
long long sum = ; while (scanf ("%d", &n) == )
{
for (int i=; i<=n; ++i) scanf ("%d", &a[i]); sum = ; int k = ;
for (int i=; i<=n-; ++i)
{
k = ;
for (int j=i+; j<=n; ++j)
{
if (a[j] % a[i] == )
{
k = j; break;
}
}
sum += k;
} printf ("%lld\n", sum);
} return ;
}

brute

暴力+降复杂度 BestCoder Round #39 1002 Mutiple的更多相关文章

  1. Manacher BestCoder Round #49 ($) 1002 Three Palindromes

    题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...

  2. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  3. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [f(n ...

  4. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  5. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

  6. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  7. HDU_6016_(Bestcoder round #92 1002)_(dfs)(暴力)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016 题意:给定男羊和女羊的朋友关系,即给定一个图,问从任意一只羊开始连续数四只不相同的羊的方法数. ...

  8. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

  9. BestCoder Round #39

    -------好久没更新博客了,发现还是需要不断总结才能进步,所以还是把最近打的一些比赛记录一下. T1:Delete (hdu 5210) 题目大意: 给出n个数,然后要删掉k个,要求剩下的数中 不 ...

随机推荐

  1. BC.36.Gunner(hash)

    Gunner  Accepts: 391  Submissions: 1397  Time Limit: 8000/4000 MS (Java/Others)  Memory Limit: 65536 ...

  2. 获取并设置ListView高度的方法

    01 public void setListViewHeightBasedOnChildren(ListView listView) {  02     ListAdapter listAdapter ...

  3. 组合数学or not ---- n选k有重

    模板问题: 1. 取物品 (comb.pas/c/cpp) [问题描述] 现在有n个物品(有可能相同),请您编程计算从中取k个有多少种不同的取法.[输入] 输入文件有两行,第一行包含两个整数n,k(2 ...

  4. MySQL5.5 RPM安装的默认安装路径

    MySQL5.5 RPM安装的默认安装路径 2011-06-20 10:34:32|  分类: MySQL|举报|字号 订阅   下载LOFTER客户端     由于一客户要求安装mysql- 5.5 ...

  5. mysql将int 时间类型格式化

    摘要 DATE_FORMAT(date,format) 根据format字符串安排date值的格式. DATE_FORMAT(date,format)  根据format字符串安排date值的格式. ...

  6. 【Python】使用 sphinx 制作简洁而又美观的文档

    参考资料: http://zh-sphinx-doc.readthedocs.io/en/latest/tutorial.html http://avnpc.com/pages/writing-bes ...

  7. 【云计算】Docker集中化web界面管理平台shipyard

    Docker集中化web界面管理平台shipyard docker shipyard seanlook                        2015年01月05日发布             ...

  8. schedule CCCallfunc CCCallfuncN CCCallfuncND

    schedule(schedule_selector(HelloWorld::step), 1.0f); void HelloWorld::step(float dt) { CCLog("d ...

  9. 【JAVA、C++】LeetCode 005 Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  10. BM算法  Boyer-Moore高质量实现代码详解与算法详解

    Boyer-Moore高质量实现代码详解与算法详解 鉴于我见到对算法本身分析非常透彻的文章以及实现的非常精巧的文章,所以就转载了,本文的贡献在于将两者结合起来,方便大家了解代码实现! 算法详解转自:h ...