码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头——枚举倍数

时间:2018-11-01 12:03:45      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:online   putc   div   att   --   names   pre   zoj   name   

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1607

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+5,M=1e6+5;
int n,a[N],c[M],mx,ans[M];
int rdn()
{
  int ret=0;bool fx=1;char ch=getchar();
  while(ch>9||ch<0){if(ch==-)fx=0;ch=getchar();}
  while(ch>=0&&ch<=9) ret=(ret<<3)+(ret<<1)+ch-0,ch=getchar();
  return fx?ret:-ret;
}
int g[20];
void wrt(int x)
{
  if(x<0)putchar(-),x=-x;
  if(!x){puts("0");return;}
  int t=0;while(x)g[++t]=x%10,x/=10;
  while(t)putchar(g[t]+0),t--;puts("");
}
int main()
{
  n=rdn();for(int i=1;i<=n;i++)a[i]=rdn(),c[a[i]]++,mx=max(mx,a[i]);
  for(int i=1;i<=mx;i++)
    if(c[i])
    for(int j=i;j<=mx;j+=i)ans[j]+=c[i];
  for(int i=1;i<=n;i++)wrt(ans[a[i]]-1);
  return 0;
}

 

bzoj 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头——枚举倍数

标签:online   putc   div   att   --   names   pre   zoj   name   

原文地址:https://www.cnblogs.com/Narh/p/9887162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!