题意:定义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. soapui groovy脚本汇总

    出处:https://www.jianshu.com/p/ce6f8a1f66f4 一.一些内部元件的访问 testRunner.testCase开头 1.向下访问 testRunner.testCa ...

  2. PHP ini 配置无效的坑给自己记录

    装redis 扩展时,发现装成功之后扩展一直加载不上, 于是phpinfo 发现Configuration File (php.ini) Path:none Loaded Configuration ...

  3. 服装类Web原型制作分享——Rodd & Gunn

    Rodd & Gunn是国外知名的服装类品牌,服装种类繁多,有衣服.帽子.穿戴饰品等. 本原型由国产Mockplus(原型工具)和iDoc(智能标注,一键切图工具)提供. 网站原型以图文排版为 ...

  4. python轻量级orm

    python下的orm使用SQLAlchemy比较多,用了一段时间感觉不顺手,主要问题是SQLAlchemy太重,所以自己写了一个orm,实现方式和netsharp类似,oql部分因为代码比较多,没有 ...

  5. android DatagramSocket send 发送数据出错

    安卓4.0以后好像不能在主线程里面使用 socket 所以不管是发送数据还是接收数据需要新开一个了线程: 以下代码是我点击发送是代码: new Thread(new Runnable() { @Ove ...

  6. fetch获取json的正确姿势

    fetch要求参数传递,遇到请求无法正常获取数据,网上其他很多版本类似这样: fetch(url ,{ method: 'POST', headers:{ 'Accept': 'application ...

  7. DB2 OLAP函数的使用

    说起 DB2 在线分析处理,可以用很好很强大来形容.这项功能特别适用于各种统计查询,这些查询用通常的SQL很难实现,或者根本就无发实现.首先,我们从一个简单的例子开始,来一步一步揭开它神秘的面纱,请看 ...

  8. Sharing Code Between Silverlight and Win8 app metro

    这里讲得很详细了: Sharing Code between Windows Phone 8 and Windows 8 Applications http://msdn.microsoft.com/ ...

  9. day06作业---字典循环

    '''1.1使⽤循环打印以下效果: ***************''' for a in range(1,6): print(a*'*') '''1.2: ***** **** *** ** * ' ...

  10. List<T>中,Remove和RemoveAt区别

    Remove删除的是匹配的第一项.比如你的list里面有2个相同的项.那么就删除第一个.后面的不删除,找不到元素和删除失败都返回falseRemoveAt是删除索引下的项