bzoj1607 [Usaco2008 Dec]Patting Heads 轻拍牛头

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1607

题目大意:给你n(n<=1e5)个数,要求对于每个数v输出,除自身以外有多少个能被v整除的数。

题目分析:暴力乱搞下就行。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int a[1100000],f[1100000],ans[110000];
int main()
{
	int n;
	n=read();
	memset(a,0,sizeof(a));
	memset(f,0,sizeof(f));
	for (int i=1;i<=n;i++)
	{
		ans[i]=read();
		a[ans[i]]++;
	}
	for (int i=1;i<=1e6;i++)
	{
		if (a[i]>0)
		for (int j=1;j<=1e6/i;j++)
		    f[i*j]+=a[i];
	}
	for (int i=1;i<=n;i++)
	    printf("%d\n",f[ans[i]]-1);
	return 0;
}


你可能感兴趣的:(bzoj1607 [Usaco2008 Dec]Patting Heads 轻拍牛头)