P2926 [USACO08DEC]拍头Patting Heads

把求约数转化为求倍数。

累计每个数出现的个数,然后枚举倍数累加答案。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#define re register
using namespace std;
void read(int &x){
static char c=getchar();x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=(x<<)+(x<<)+(c^),c=getchar();
}
void output(int x){
if(!x){putchar();return;}
static int wt[],l=;
while(x) wt[++l]=x%,x/=;
while(l) putchar(wt[l--]+);
}
#define N 1000001
int n,a[],d[N],f[N];
int main(){
read(n);
for(re int i=;i<=n;++i) read(a[i]),++d[a[i]];
for(re int i=;i<N;++i){
if(!d[i]) continue;
for(re int j=;j*i<N;++j) f[j*i]+=d[i];
}
for(re int i=;i<=n;++i)
output(f[a[i]]-),putchar('\n');//扣掉自己
return ;
}

bzoj1607 / P2926 [USACO08DEC]拍头Patting Heads的更多相关文章

  1. 洛谷 P2926 [USACO08DEC]拍头Patting Heads

    P2926 [USACO08DEC]拍头Patting Heads 题目描述 It's Bessie's birthday and time for party games! Bessie has i ...

  2. 【题解】洛谷P2926 [USACO08DEC]拍头Patting Heads

    洛谷P2926:https://www.luogu.org/problemnew/show/P2926 思路 对于每一个出现的数 从1到Max 凡是这个数的倍数 那么ans就加上他的个数 PS:最后要 ...

  3. [USACO08DEC]拍头Patting Heads 数学 BZOJ 1607

    题目描述 It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 1 ...

  4. [USACO08DEC]拍头Patting Heads 水题

    类似素数筛,暴力可过,不需要太多的优化 Code: #include<cstdio> #include<algorithm> #include<string> us ...

  5. BZOJ-1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法+乱搞

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 1383 Solved: 7 ...

  6. [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学

    Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...

  7. BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lyds ...

  8. BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Description   今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏.     贝茜让N(1≤N≤10 ...

  9. 浅谈桶排思想及[USACO08DEC]Patting Heads 题解

    一.桶排思想 1.通过构建n个空桶再将待排各个元素分配到每个桶.而此时有可能每个桶的元素数量不一样,可能会出现这样的情况:有的桶没有放任何元素,有的桶只有一个元素,有的桶不止一个元素可能会是2+: 2 ...

随机推荐

  1. Spring学习笔记--初始化和销毁Bean

    可以使用bean的init-method和destroy-method属性来初始化和销毁bean.定义一个Hero类: package com.moonlit.myspring; public cla ...

  2. poj_2752 kmp

    题目大意 给定字符串S,求出S的所有可能相同前后缀的长度.比如: "alala"的前缀分别为{"a", "al", "ala&qu ...

  3. 【WebService】快速构建WebService示例

    package com.slp.webservice; import javax.jws.WebService; /** * Created by sanglp on 2017/2/25. * 接口 ...

  4. this、target、currentTarget

    this:绑定事件所触发行为的对象 target:最开始冒泡的的对象 currentTarget:事件触发行为的对象 this == target currentTarget和this 是target ...

  5. salt-stack更换主机名

    author:headsen  chen date: 2018-09-30  11:22:40 1,建立master端和client端的正常连接 #master yum -y install epel ...

  6. Android中Log机制详解

    Android中Log的输出有如下几种: Log.v(String tag, String msg);        //VERBOSELog.d(String tag, String msg);   ...

  7. 2-sat+二分搜索hdu(3622)

    hdu3622 Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  8. ibatis 中#和 $ 符号的区别

    1.数据类型匹配 #:会进行预编译,而且进行类型匹配(自动确定数据类型): $:不进行数据类型匹配. 2.实现方式: # 用于变量替换(先生成一个占位符,然后替换) select * from use ...

  9. Oracle Schema Objects——PARTITION

    Oracle Schema Objects 表分区 表- - 分区( partition )TABLE PARTITION 一段时间给出一个分区,这样方便数据的管理. 可以按照范围range分区,列表 ...

  10. nginx 与 浏览器缓存

    一.本地静态文件 location /html/{ rewrite ^(html/.*)$ /$1 break; root /data/static; expires 12h; etag off; i ...