CF215E.Periodical Numbers

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A non-empty string s is called binary, if it consists only of characters "0" and "1". Let's number the characters of binary string s from 1 to the string's length and let's denote the i-th character in string s as s__i.

Binary string s with length n is periodical, if there is an integer 1 ≤ k < n such that:

  • k is a divisor of number n
  • for all 1 ≤ i ≤ n - k, the following condition fulfills: s__i = s__i + k

For example, binary strings "101010" and "11" are periodical and "10" and "10010" are not.

A positive integer x is periodical, if its binary representation (without leading zeroes) is a periodic string.

Your task is to calculate, how many periodic numbers are in the interval from l to r (both ends are included).

一个非空字符串 ss 被称为二进制串,当且仅当它仅由字符 "0" 和 "1" 组成。我们对二进制串 ss 的字符从 11 编号至其长度,并记 ss 的第 ii 个字符为 sis_i。

长度为 nn 的二进制串 ss 称为周期串,若存在整数 1≤k<n1 \leq k < n,满足:

  • kk 是 nn 的约数;
  • 对所有 1≤i≤n−k1 \leq i \leq n - k,均有 si=si+ks_i = s_{i + k}。

例如,二进制串 "101010" 和 "11" 是周期串,而 "10" 和 "10010" 不是。

一个正整数 xx 称为周期数,若其二进制表示(不含前导零)是一个周期串。

你的任务是计算区间 [l,r][l, r](含端点)内周期数的个数。

输入格式

The single input line contains two integers l and r (1 ≤ l ≤ r ≤ 1018). The numbers are separated by a space.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

单行输入包含两个整数 ll 和 rr(1 ≤ l ≤ r ≤ 10181 ≤ l ≤ r ≤ 10^{18}),两数之间用空格分隔。

请注意:在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。

输出格式

Print a single integer, showing how many periodic numbers are in the interval from l to r (both ends are included).

输出一个整数,表示区间 [l,r][l, r](两端均包含)内周期数的个数。

输入输出样例

  • 输入#1

    1 10

    输出#1

    3
  • 输入#2

    25 38

    输出#2

    2

说明/提示

In the first sample periodic numbers are 3, 7 and 10.

In the second sample periodic numbers are 31 and 36.

在第一个样例中,循环数为 3、7 和 10。

在第二个样例中,循环数为 31 和 36。

输入解题思路,AI测评打分。不知道怎么写?

首页