题意:定义S(n) = n*各数位之积,然后给定L<=R<=10^18,求有多少个n在[L,R]区间内

思路:

看了半天无从下手。。看完题解才豁然开朗。。

具体思路看vani神博客吧。讲的很清楚。。

code:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = ;
const ll Inf = 1000000000LL;
int d[maxn], dc[maxn][], tot;
int td, tc[]; void dfs(int r, int s, ll num){
if (num > Inf) return;
if (r == || s == ){
d[tot] = num;
for (int i = ; i < ; ++i)
dc[tot][i] = tc[i];
tot++;
return;
}
dfs(r + , s, num);
tc[r-]++;
dfs(r, s + , num * r);
tc[r-]--;
} ll frac[];
ll count(int m){
int left = m;
ll res = frac[m];
for (int i = ; i < ; ++i) left -= tc[i], res /= frac[tc[i]];
res /= frac[left];
return res;
} int bit[]; ll calculate(ll b, int p){
if (b <= ) return ;
int k = ;
while (b > ) bit[++k] = b % , b /= ;
int size = ;
for (int i = ; i < ; ++i)
tc[i] = dc[p][i], size += tc[i];
ll res = ;
for (int i = ; i < k; ++i)
if (i >= size) res += count(i);
for ( ;k > ; --k){
if (bit[k] == || size > k) break;
for (int i = ; i < bit[k]; ++i) if (tc[i-]){
--tc[i-], --size;
if (k > size) res += count(k - );
++tc[i-], ++size;
}
if (bit[k] >= ){
if (k > size) res += count(k-);
if (tc[bit[k]-] == ) break;
--tc[bit[k]-], --size;
}
}
return res;
} ll calculate(ll x){
if (x <= ) return ;
ll res = ;
for (int i = ; i < tot; ++i)
res += calculate(x / d[i] + , i);
return res;
} void pre_do(){
frac[] = ;
for (int i = ; i <= ; ++i) frac[i] = frac[i-] * i;
memset(tc, , sizeof(tc));
tot = ;
dfs(, , );
} int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
pre_do();
ll l, r;
while (cin >> l >> r){
ll ans = calculate(r) - calculate(l - );
cout << ans << endl;
}
return ;
}

[violet2]sillyz的更多相关文章

  1. Atitit.软件命名空间  包的命名统计 及命名表(2000个名称) 方案java package

    Atitit.软件命名空间  包的命名统计 及命名表(2000个名称) 方案java package 1. 统计的lib jar 列表1 2. Code3 3. 常用包名按找字母排序(2000个)4 ...

随机推荐

  1. nodejs 开发服务端 child_process 调试方法(1)

    由于最近正在做一个服务端项目,采用了nodejs引擎开发,主要是master-worker工作机制;主进程可以直接调试,但是子进程调试好像有点麻烦,我没有找到好的方法; worker这里,我分拆成了几 ...

  2. python 找出一篇文章中出现次数最多的10个单词

    #!/usr/bin/python #Filename: readlinepy.py import sys,re urldir=r"C:\python27\a.txt" disto ...

  3. Codeforces 757B. Bash's Big Day GCD

    B. Bash's Big Day time limit per test:2 seconds memory limit per test:512 megabytes input:standard i ...

  4. [ES]elasticsearch章1 ES各角色的分工

    es集群里的master node.data node和client node到底是怎么个意思,分别有何特点? master节点 主要功能是维护元数据,管理集群各个节点的状态,数据的导入和查询都不会走 ...

  5. Angular的一些用法或者结构技巧

    如果有更好的方式,请留言交流: 2017-07-07 多个controller共用一个函数.在$rootScope中定义方法, $rootScope.share_fun = function test ...

  6. mybatis学习 九 代理开发

    1.作用: 实现创建一个接口后把mapper.xml由mybatis生成接口的实现类,通过调用接口对象就可以获取 mapper.xml 中编写的 sql. 2.实现步骤: 2.1 创建一个接口 (1) ...

  7. Syslog和Windows事件日志收集

    Syslog和Windows事件日志收集 EventLog Analyzer从分布式Windows设备收集事件日志,或从分布式Linux和UNIX设备.交换机和路由器(Cisco)收集syslog.事 ...

  8. 55.UIbutton点击切换颜色

    #import "ViewController.h" #define width_w     [UIScreen mainScreen].bounds.size.width #de ...

  9. Mybatis-Plus 实战完整学习笔记(三)------导入MybatisPlus环境

    1.dao层接口引入 package com.baidu.www.mplus.mapper; import com.baidu.www.mplus.bean.Employee; import com. ...

  10. Promise.all函数的使用

    Promise.all([this.getCity('guess'),this.getCity('hot'),this.getCity('group')]).then(res=>{ // con ...