# bzoj1607: Tap the bull's head

Source: Internet
Author: User

1607: [Usaco2008 dec]patting Heads Pat Bull head time limit:3 Sec Memory limit:64 MB
submit:1162 solved:602
[Submit] [Status] [Discuss] Descriptiontoday is Betsy's birthday, in order to celebrate her birthday, Bessie invited you to play a game. Bessie Let N (1≤n≤100000) head cows sit in a circle. In addition to the 1th and n cows, the I cows are adjacent to the i-l and i+l cows. n cows are adjacent to the No. 1th Cow. The farmer John filled a bucket with a lot of notes, each containing a unique number from 1 to 1,000,000. then each cow I take a note from the handle of the AI. Each cow turns on a lap and beats all the numbers that divide the number on the note, and then goes back to its original position. The cows want you to help them determine that each cow needs to be slapped. Inputline 1th contains an integer n, and the next 2nd to N+1 row contains an integer AI for each row. Outputrows 1th through N, the output of each row indicates the number of cows to be slapped by the first cow. Sample Input5//There are five numbers, for any number, the number of other numbers is its approximate
2
1
2
3
4

INPUT DETAILS:

The 5 cows is given the numbers 2, 1, 2, 3, and 4, respectively.

Sample Output2
0
2
1
3

OUTPUT DETAILS:

The first cow pats the second and third cows; The second cows pats no cows;
etc.
HINT Source

Silver

First write is right, but did not take into account if the number of input is very likely to appear a lot of the same number of cases, so search to find the optimized version of the optimization, and add read-in optimization, and then probably the state is not good to see the array opened small, 2333 cold TMTMTM

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace Std;
int a[100005],f[1000005],v[1000005];
int x=0;
Char C=getchar ();
while (c< ' 0 ' | | C> ' 9 ') C=getchar ();
while (c>= ' 0 ' &&c<= ' 9 ') {
x=x*10+c-' 0 ';
C=getchar ();
}
return x;
}
int main () {
memset (F,0,sizeof (f));
memset (v,0,sizeof (v));
int n,maxn=-1;
for (int i=1;i<=n;i++) {
Maxn=max (A[I],MAXN);
v[a[i]]++;
}
for (int i=1;i<=maxn;i++) {
if (V[i]) {
for (int j=i;j<=maxn;j+=i)
F[j]+=v[i];
}
}
for (int i=1;i<=n;i++)
printf ("%d\n", f[a[i]]-1);
return 0;
}

Related Keywords:

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.