1607 [Usaco2008 dec]patting Heads Pat Bull Head

Source: Internet
Author: User

The main question: in the number of N, for each of the number, in the other (n-1) the number of several is his factor.

The puzzle: Considering that the range of the AI is not too large, you can use a bucket to count the number of 1~max (AI), and then sift the 1~max in multiples of MAX. 100,000 numbers in 1000000 barrels are very sparse, ignoring the number of occurrences of 0 is very important for time efficiency.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <cctype>5#include <iostream>6 using namespacestd;7 #defineMaxx 10000078 #defineMAXN 2333339 #definell Long LongTen inta[maxn],num[maxx],n,max=0; One ll F[maxx]; A intQread () - { -     CharCints=0, t=1; the      while(!isdigit (C=getchar ()))if(c=='-') t=-1; -      Do{s=s*Ten+c-'0';} while(IsDigit (c=GetChar ())); -     returns*T; - } + intMain () - { +n=Qread (); Amemset (NUM,0,sizeof(num)); at      for(intI=1; i<=n;i++) A[i]=qread (), num[a[i]]++,max=Max (A[i],max); -      for(intI=1; i<=max;i++) -         if(Num[i]) for(intJ=i;j<=max;j+=i) f[j]+=Num[i]; -      for(intI=1; i<=n;i++) printf ("%lld\n", f[a[i]]-1); -     return 0; -}
View Code

1607 [Usaco2008 dec]patting Heads Pat Bull Head

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.