您的位置:首页 > 其它

CodeForces 215E 数位DP

2013-04-15 14:44 363 查看
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
LL dp[66];
int dig(LL n) {
int s = 0;
while(n) {s++; n >>=1;}
return s;
}
LL f(int len, int t, LL n, bool lim) {
if(!lim) return 1LL<<(t-1);
LL tp = 1;
int i;
for(i = 1; i <len/t; i++) tp = (tp<<t)+1;
LL ret = n/tp - (1LL<<(t-1))+1;
if(ret < 0) ret = 0;
return ret;
}
LL gao(LL n) {
int len = dig(n);
int i, j, k;
LL ans = 0;
for(i = 2; i <= len; i++) {
memset(dp, 0, sizeof(dp));
for(j = 1; j < i; j++) if(i%j==0){
dp[j] = f(i, j, n, i==len);
for(k = 1; k < j; k++) if(j%k==0)
dp[j] -= dp[k];
ans += dp[j];
}
}
return ans;
}
int main() {
LL l, r;
cin >> l >> r;
cout << gao(r) - gao(l-1) << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: