Periodical Numbers

我们先按长度分类对于当前处理的长度k, 我们令 F[ i ] 为有长度为 i 的循环节的方案数。

然后容斥出f[ i ] 表示最小循环节是 i 的方案数, 然后加起来。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);using namespace std;const int N = 100 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}LL l, r;
int a[N];
LL f[N];LL getVal(int l, int r) {LL ans = 0;for(int i = l; i <= r; i++) ans *= 2, ans += a[i];return ans;
}LL solve(LL x) {if(x <= 1) return 0;int tot = 0;for(LL i = x; i; i /= 2) a[tot++] = i % 2;reverse(a, a + tot);vector<int> fac;vector<LL> way;LL ans = 0;for(int i = 2; i < tot; i++) {fac.clear(); way.clear();for(int j = 1; j < i; j++) {if(i % j) continue;fac.push_back(j);}way.resize(SZ(fac));for(int j = 0; j < SZ(way); j++)way[j] = 1LL << (fac[j] - 1);for(int j = 0; j < SZ(way); j++) {ans += way[j];for(int k = j + 1; k < SZ(way); k++) {if(fac[k] % fac[j] == 0) way[k] -= way[j];}}}fac.clear(); way.clear();for(int i = 1; i < tot; i++) {if(tot % i == 0) fac.push_back(i);}way.resize(SZ(fac));for(int j = 0; j < SZ(way); j++) {LL val = getVal(0, fac[j] - 1);way[j] = max(val - (1ll << (fac[j] - 1)), 0ll);bool flag = true;for(int k = fac[j]; k + fac[j] - 1 < tot; k += fac[j]) {LL tmp = getVal(k, k + fac[j] - 1);if(tmp > val) break;if(tmp < val) {flag = false;break;}}way[j] += flag;}for(int j = 0; j < SZ(way); j++) {ans += way[j];for(int k = j + 1; k < SZ(way); k++) {if(fac[k] % fac[j] == 0) way[k] -= way[j];}}return ans;
}int main() {scanf("%lld%lld", &l, &r);printf("%lld", solve(r) - solve(l - 1));return 0;
}/*
*/

转载于:https://www.cnblogs.com/CJLHY/p/10833575.html

Codeforces 215E Periodical Numbers 容斥原理相关推荐

  1. CodeForces 215E Periodical Numbers 数位DP

    这题做了有好几天了,终于过了= = 完全不懂网上题解的递推写法,只能自己用记忆化搜索瞎搞,总算是搞出来了. 具体策略就是记忆化搜索的时候用一个tmp数组记录最前面len个的值,然后后面的数字必须要和前 ...

  2. CodeForces 215E Periodical Numbers 数位DP

    题意:给你一个区间[l,r],求这个区间内满足条件的数,条件是:这个数的二进制表示时,dig[i] == dig[i+k],(0<k<len,且len%k==0,len为这个数的二进制代码 ...

  3. codeforces215 E. Periodical Numbers(不一样的数位dp) 模板

    E. Periodical Numbers  time limit per test  2 seconds  memory limit per test  256 megabytes  input  ...

  4. codeforces215 E. Periodical Numbers(数位dp)

    E. Periodical Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. CodeForces 215 E.Periodical Numbers(组合数学+dp)

    Description 给出一个区间[L,R][L,R],问这个区间中有多少数字的二进制表示是有循环节的 Input 两个正整数L,RL,R(1≤L≤R≤1018)(1\le L\le R\le 10 ...

  6. CodeForces - 55D Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:求区间[L,R]有多少个Beautiful numbers.Beautiful number ...

  7. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  8. CodeForces - 165E Compatible Numbers(SOSdp)

    题目链接:点击查看 题目大意:给出 nnn 个数,问能否在数列中找到一个数,满足 ai&aj=0a_i\& a_j=0ai​&aj​=0 题目分析:题目中的式子可以转换为,ai ...

  9. Codeforces 1326F Wise Men (容斥原理、状压 DP、划分数)

    题目链接 F1: https://codeforces.com/contest/1326/problem/F1 F2: https://codeforces.com/contest/1326/prob ...

最新文章

  1. eclipselink mysql_Eclipse连接MySQL数据库(傻瓜篇)
  2. 不安装Oracle使用cx_Oracle
  3. Nodejs教程14:querystring模块
  4. 【迁移学习(Transfer L)全面指南】元学习
  5. Oracle数据类型简介【转贴】
  6. ubuntu下不同版本python安装pip及pip的使用
  7. 不属于计算机常用软件日常应用的是,综合技能实践+计算机常用应用软件的安装和使用指导 (1)...
  8. php中如何使用phpredis
  9. HTTP Content-Type类型
  10. 上海市二级c语言软件环境,上海市计算机二级C语言复习资料 word整理版.doc
  11. 浅谈Solr和ElasticSearch建索引性能优化策略
  12. mysql的模拟数据,员工的模拟数据,sql语句的应用,粘贴即用
  13. 华为android手机root,华为手机root权限获取教程
  14. python文本挖掘教程,4个步骤教你轻松完成文本挖掘预处理(附python代码)
  15. 三轴加速度传感器角度值转换原理
  16. .7z文件 合并、解压
  17. android的版本电视怎么投屏,三星电视怎么投屏 三星电视投屏设置方法
  18. 用计算机弹生僻字乐谱,抖音生僻字计算器乐谱 抖音生僻字计算器数字简谱
  19. 汽车GPS定位器在汽车金融风控中如何把控
  20. 微信小程序 首行缩进、 去掉/取消首行缩进

热门文章

  1. 配置SQL SERVER远程连接以及kettle连接SQL SERVER
  2. KTV消费(会员)管理系统
  3. linux配置微信支付的api证书,API证书及密钥
  4. UVALive - 4380 Javanese Cryptoanalysis
  5. Swing布局管理器
  6. 一个总经理的11个面试问题
  7. hadoop学习笔记于骑士物语,感谢骑士感谢赵老师。
  8. 基于Java的商品推荐系统
  9. marathon-lb-什么是服务发现?(转)
  10. Flexslider - 响应式的 jQuery 内容滚动插件