Tau tap number submultiple ---------

Today is Bessie's birthday, to celebrate his birthday, Bessie invite you to play a game. Bessie let NN

Cows (No. 11

To NN

) Sit in a circle. In addition to 11

Number and NN

No. outer cows, ii

Cow number and i-1i-1

And the number i + 1i + 1

No. neighboring cows, NN

No. 11 cows and

No. neighboring cows. Farmer John with a bucket filled with a lot of paper, every piece of paper that contains a 11

To 10,000,001,000,000

Between the numbers. Then each cow ii

A note taken out from the barrel, with the numbers on paper AiAi

Representation. After you've selected all the cows, each cow took to turn around, when a cow walked beside their own hands if the numbers can be digitally divisible by the hands of the cows, the head of the cow pat. Cattle hope you help them determine, for each cow needs to beat the number of cattle. That is a total of NN

Integers A1, A2, ..., ANA1, A2, ..., AN

, For every number AiAi

, Find other numbers in how many it is about numbers. The first row contains an integer input format NN

. Next NN

Rows, each row contains an integer AiAi

. Total output format NN

Line, page ii

Ii digital line for the first

The number of cows need to beat the cattle. Data range 1≤N≤1051≤N≤105

,
1≤Ai≤1061≤Ai≤106

Sample input: 5
2
. 1
2
. 3
. 4
Output Sample: 2
0
2
. 1
. 3

Ideas: Reverse seek every number which is a divisor of several numbers

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1000010;
int n;
int a[N], cnt[N], s[N];
int main(){
 scanf("%d", &n);
 for (int i = 0; i < n; i ++){
  scanf("%d", &a[i]);
  cnt[a[i]] ++;
 }
 for (int i = 1; i <= N; i ++)
   for (int j = i; j <= N; j += i)
    s[j] += cnt[i];
    for (int i = 0; i < n; i ++)   printf("%d\n", s[a[i]] - 1);
  return 0;
}
Published 106 original articles · won praise 67 · views 5426

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/104950905