Logo
(追記) (追記ここまで)

3870번 - Find the Multiples 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB59232245.833%

문제

You are given a sequence a0a1···aN−1 of digits and a prime number Q. For each i ≤ j with ai ≠ 0, the subsequence aiai+1···aj can be read as a decimal representation of a positive integer. Subsequences with leading zeros are not considered. Your task is to count the number of pairs (i, j) such that the corresponding subsequence is a multiple of Q.

입력

The input consists of at most 50 datasets. Each dataset is represented by a line containing four integers N, S, W, and Q, separated by spaces, where 1 ≤ N ≤ 105, 1 ≤ S ≤ 109, 1 ≤ W ≤ 109, and Q is a prime number less than 108. The sequence a0 ··· aN−1 of length N is generated by the following code, in which ai is written as a[i].

int g = S;
for(int i=0; i<N; i++) {
  a[i] = (g/7) % 10;
  if( g%2 == 0 ) { g = (g/2); }
  else      { g = (g/2) ^ W; }
}

Note: the operators /, %, and ^ are the integer division, the modulo, and the bitwise exclusiveor, respectively. The above code is meant to be a random number generator. The intended solution does not rely on the way how the sequence is generated.

The end of the input is indicated by a line containing four zeros separated by spaces.

출력

For each dataset, output the answer in a line. You may assume that the answer is less than 230.

제한

예제 입력 1

3 32 64 7
4 35 89 5
5 555 442 3
5 777 465 11
100000 666 701622763 65537
0 0 0 0

예제 출력 1

2
4
6
3
68530

힌트

In the first dataset, the sequence is 421. We can find two multiples of Q = 7, namely, 42 and 21.

In the second dataset, the sequence is 5052, from which we can find 5, 50, 505, and 5 being the multiples of Q = 5. Notice that we don’t count 0 or 05 since they are not a valid representation of positive integers. Also notice that we count 5 twice, because it occurs twice in different positions.

In the third and fourth datasets, the sequences are 95073 and 12221, respectively.

출처

ICPC > Regionals > Asia Pacific > Japan > Asia Regional Contest 2010 in Tokyo F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /