icodelab circling another game

description

Teacher let n (1 <= n <= 100000) two children in a circle, and the first students k k + 1 k-1 and a first adjacent students, No. 1 and No. n students adjacent to students, teachers a bag and put a lot of numbers written note, the plurality of digits may be on the same paper, and num is the range of numbers 1 <= num <= 1000000. Then each student i from the bag and pulled out a piece of paper Ai, each student walk around, and divisible by tapping the note numbers of students back, then go back to their positions. Each student requires you to calculate the total number of students pat my back.

Entry

The first row contains an integer n, the next n lines, each line of input integer Ai.

Export

A total of n output lines, each line a number that represents the number of students beat other students.

Sample input 1

5
2
1
2
3 
4

Sample Output 1

2
0
2
1
3

Ideas:

See Notes (skin look very happy)

Code:

 

#include <bits / STDC ++ H.> 
the using namespace STD; 
int A [10,000,005]; 
int n-, MX = -100; 
int B [1000005]; 
int CNT [1000005]; 
void get_factor () { 
    for (int I =. 1 ; i <= 1000000; i ++ ) {// title number does not exceed described 100W 
        IF (B [I]) Continue;! // number must be present, is not present is skipped 
        for (int j = 1; j <= 1000000 / i; j ++) { 
        	// b [i * j] is true, this figure represents a i j times also exist, then obviously i * j divisible i, 
			// so we have to count this number be i * j how many times when it is divisible by the number of times i put that number appears accumulate up 
			// i is the number of times this number appears b [i] 
			number // we cnt [i * j] to the cumulative i * j is divisible by that number, so there CNT [I * j] = B + [I]; 
             IF (B [I * j]) CNT [I * j] = B + [I]; 
             
             // this place is critical because one starts from j , so put their own divisible by that time lost  
             // j but initialization is required from the start from 1 rather than 2, because i figure there may be a number
             // in fact, following this sentence can not, then subtract 1, and the output cnt [a [i]] where output answers --1 it.
             IF (I * J == I) CNT [I] -; 
             
        }        
    } 
} 
int main () { 
    Scanf ( "% D", n &); // n individual input 
    for (int i = 1; i <= n ; I ++) { 
        Scanf ( "% D", a & [I]); // for each input digital hands of 
        b [a [i]] ++ ; // because the number of each of the hands may be repeated, so use bucket algorithm 
    } 
    get_factor (); 
    for (int I =. 1; I <= n-; I ++) 
        COUT << CNT [A [I]] << endl; 
    return 0; 
}

 

 

 

 

Guess you like

Origin www.cnblogs.com/mysh/p/11291551.html