题意:定义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. 抽屉效果几大github第三方库

    首先感谢董铂然博客园,鄙人收藏学习之用,如有朋友看到.有需要请直接前往董铂然博客园本文, 请点击查看原文 在公司项目新版本方案选择中,对主导航中要使用的抽屉效果进行了调研.主要原因是旧的项目中所用的库 ...

  2. Luogu 1169 [ZJOI2007]棋盘制作 - 动态规划+单调栈

    Description 给一个01矩阵, 求出最大的01交错的正方形和最大的01交错的矩阵 Solution 用动态规划求出最大的正方形, 用单调栈求出最大的矩阵. 在这里仅介绍求出最大正方形(求最大 ...

  3. vs2010打开qt的.pro文件时错误解决办法

    注意:qt creator工程中一般都已经存在*.pro文件,里面存放着一些自己配置的包含头文件和lib库文的信息,最好不要再重新使用qmake -project生成,若重新生成,则可能要重新增加配置 ...

  4. Python generator 的yield (enumerate)

    生成杨辉三角 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 def triangles(max): L = [1,] while len(L) - 1 < ...

  5. BUG(1):一个关于指针的bug

    是时候记录一下这个让我栽了两次的bug了. 具体情况如下: #include <stdio.h>#include <stdlib.h> struct app_info_t { ...

  6. Python之路(第一篇):Python简介和基础

    一.开发简介 1.开发:      开发语言:               高级语言:python.JAVA.PHP.C#..ruby.Go-->字节码                低级语言: ...

  7. PHP去除重复的数组数据

    PHP去除重复的数组数据 <?php $input = array("a" => "green","", "red&q ...

  8. flask 中文编码解码

    process.append("中文") print(process) # return Response(json.dumps(process), mimetype='appli ...

  9. ExportGrid Aspose.Cells.dll

    using Aspose.Cells; using Aspose.Words; using System; using System.Collections; using System.Collect ...

  10. Sliding Window Maximum LT239

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...