[BZOJ1607] [Usaco2008 Dec] Patting Heads Tap Bull Head (math)

Source: Internet
Author: User

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 on the hand to divide the number of the cow's head into 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.
HINTSource

Silver

Solution

The original test instructions wrong, here made a small amendment.

Using a method like a prime sieve, when a number is sifted, it indicates which cows hold the number.

Perceptual understanding, do not understand the code.

(as the only question on page 7th is not the title of the title I would not Qaq)

1#include <bits/stdc++.h>2 using namespacestd;3 inta[100005], b[1000005], ans[1000005];4 intMain ()5 {6     intN, mx =0;7scanf"%d", &n);8      for(inti =1; I <= N; i++)9     {Tenscanf"%d", A +i); Oneb[a[i]]++; AMX =max (MX, a[i]); -     } -      for(inti =1; I <= MX; i++) the         if(B[i]) -              for(intj =1; I * j <= mx; J + +) -Ans[i * j] + =B[i]; -      for(inti =1; I <= N; i++) +printf"%d\n", Ans[a[i]]-1); -     return 0; +}
View Code

[BZOJ1607] [Usaco2008 Dec] Patting Heads Tap Bull Head (math)

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.