Блог пользователя virus_1010

Автор virus_1010, история, 7 лет назад, По-английски

Given T(1 <= T <= 1e5) the no. of test cases.
Each testcase contains an integer N(1 <= N <= 1e18).
We define F(x) as the xor of all the digits in x.
Find (summation of F(x) where x goes from 1 to N) for each testcase.
Can anyone help me with this?

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by virus_1010 (previous revision, new revision, compare).

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by virus_1010 (previous revision, new revision, compare).

»
7 лет назад, # |
Rev. 6   Проголосовать: нравится +2 Проголосовать: не нравится

simple digits dp — xor of digits <= 15. So dp[l][y][z][x] = number of len-(l+1) numbers, y denotes if number is non-prefix or not, z if number is non-zero or not, x the current xor — try current digit(c) 0-9(check c's possibility — (y||(c<=N[l])) then add dp[l-1][y||(c<N[l]][z||c][x^c]; write proper base cases.
For final answer, add (number of numbers for each xor<=15) * xor.

Time complexity — O(log(N)*64);