Can some one help me on how to solve this problem?

Editorial is given in Japanese, i used google translater to understand it but some sentence doesn't make any sense to me and i couldn't understand solution from editorial.

Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years.
×

# | User | Rating |
---|---|---|

1 | MiFaFaOvO | 3681 |

2 | tourist | 3496 |

3 | apiadu | 3438 |

4 | TLE | 3356 |

5 | LHiC | 3339 |

6 | mnbvmar | 3281 |

7 | 300iq | 3267 |

8 | Radewoosh | 3242 |

9 | yosupo | 3233 |

10 | 1919810 | 3203 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 190 |

2 | antontrygubO_o | 186 |

3 | tourist | 182 |

4 | Radewoosh | 168 |

4 | vovuh | 168 |

6 | pikmike | 166 |

7 | ko_osaga | 161 |

8 | Um_nik | 160 |

9 | Petr | 154 |

10 | McDic | 152 |

Can some one help me on how to solve this problem?

Editorial is given in Japanese, i used google translater to understand it but some sentence doesn't make any sense to me and i couldn't understand solution from editorial.

↑

↓

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/24/2020 12:30:14 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Problem tag — Digit DP.

Here is my submission, which you can refer to: Atcoder Submission 8567969

I don't know the solution of the editorial, just give it on my own.

Prerequesite knowledge: For every $$$a, b \in \mathbb{N}$$$ then $$$a+b = a\oplus b + 2\times (a\ and\ b) =(a\ or\ b) + (a\ and\ b)$$$. Well this is easy to prove.

Therefore let $$$x = a\ or\ b,\ y = a\ and\ b,\ u = a\oplus b,\ v = a+b$$$ then $$$x+y = v, x-y = u$$$. So for each pair $$$(u, v)$$$ in the answer maps with exactly one pair $$$(x, y)$$$, and each pair $$$(x, y)$$$ such that $$$y \subseteq x, y \le x \le N$$$ corresponds with only one pair $$$(u, v)$$$. Here $$$y \subseteq x$$$ means in binary representation, each bit of $$$y$$$ is smaller than the corresponding bit of $$$x$$$.

So we can count the number of pair $$$(a, b)$$$ such that $$$b \subseteq a, a+b \le N$$$.

Let say in binary representation, $$$a = \overline{a_{60}a_{59}...a_{1}a_{0}}$$$ and $$$b = \overline{b_{60}b_{59}...b_{1}b_{0}}$$$ then we can solve the problem using Digit DP. You can refer to my solution.

Thanks a lot for your explanation

i'm newbie to CP and didn't understand your explaination could u please elaborate how we can count the no. of pairs (x,y) such that y⊆x,y≤x≤N given that N <= 10^18 it will not pass the time limit.

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