[Usaco2008 DEC] patting heads

Source: Internet
Author: User
Description today is Bessie's birthday. To celebrate her birthday, Bessie invites you to play a game. bessie sat N (1 ≤ n ≤ 100000) cows in a circle. in addition to cows 1 and N, cows I are adjacent to cows I-l and I + L. the number N is adjacent to the number 1. farmer John filled a bucket with a lot of paper, each containing a unique number ranging from 1 to 1,000,000. then each cow I took a piece of paper from the handle AI. each cow takes turns to take a lap, and simultaneously beats the heads of the cows whose numbers can be divisible by the numbers on the paper, and then returns to the original position. the cows want you to help them determine which cows need to beat. the input 1st line contains an integer N, And the next 2nd to n + 1 line contains an integer AI. output 1st to N rows. The output of each row indicates the number of cows to be tapped by the I-th cow. sample input5 // There are five numbers. For any number, the number of other numbers is its approximate number.
2
1
2
3
4

Input details:

The 5 cows are 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.

 

Question:

Screening method;

It's quite simple.-I am also drunk because I am too sleepy to see the wrong scope;

After reviewing the screening method, I think noip may also be used to test the screening method. After all, it is not difficult;

 

Code and some comments are attached:

# Include <cstdio> # include <cstring> # include <algorithm> # include <iostream> using namespace STD; const int maxn = 1000010; int N; int A [100010], CNT [maxn]; int sum [100010]; int X, Maxx; int main () {freopen ("patheads. in "," r ", stdin); freopen (" patheads. out "," W ", stdout); scanf (" % d ", & N); For (INT I = 1; I <= N; I ++) {scanf ("% d", & A [I]); CNT [A [I] ++; // number of records; Maxx = max (Maxx, A [I]); // mark the maximum value, optimization time} For (INT I = 1; I <= Maxx; I ++) {If (CNT [I]) {for (Int J = I; j <= Maxx; j + = I) {// J + = I can ensure that the relationship is a multiple; sum [J] + = CNT [I] ;}} for (INT I = 1; I <= N; I ++) printf ("% d \ n", sum [A [I]-1); // deduct yourself, because the number of records at the beginning is included in return 0 ;}

 

[Usaco2008 DEC] patting heads

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.