K-lucky-number(0917)

问题描述

K-lucky-number is defined as add up the number of each bit is a multiple of K.for example, 24 is a 3-lucky-number,because 2+4=6, 6 is a multiple of 3.Now, there is a closed interval from L to R, please output the sum of squares of the K-lucky-number in this interval.

输入

The first line of input is the number of test cases T.

For each test case have one line contains three integer L, R, K(0<L<=R<10^9, 1<k<30).

输出

For each test case output the answer the sum of squares of the K-lucky-number in this interval and mod 1000000007.

样例输入

2
1 10 6
100 1000 7

样例输出

36
46057247

有点6、= =

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define ll long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define N 50 struct Node{
ll cnt,sum,sqsum; //个数,和,平方和
}; int l,r,k;
int bit[N];
ll p10[N];
Node dp[N][N]; void init()
{
p10[]=;
for(int i=;i<=;i++) p10[i]=p10[i-]*%MOD;
}
Node dfs(int pos,int mod,bool limit)
{
Node ans;
ans.cnt=ans.sum=ans.sqsum=;
if(pos==-){
if(!mod) ans.cnt=;
else ans.cnt=;
return ans;
}
if(!limit && dp[pos][mod].sum!=-) return dp[pos][mod];
int end=limit?bit[pos]:;
for(int i=;i<=end;i++){
Node tmp=dfs(pos-,(mod+i)%k,(i==end)&&limit);
ans.cnt=(ans.cnt+tmp.cnt)%MOD;
ans.sum=(ans.sum + tmp.sum + i*p10[pos]%MOD*tmp.cnt%MOD)%MOD;
ans.sqsum=(ans.sqsum + i*i*p10[pos]%MOD*p10[pos]%MOD*tmp.cnt%MOD + *i*p10[pos]%MOD*tmp.sum%MOD + tmp.sqsum)%MOD;
}
if(!limit) dp[pos][mod]=ans;
return ans;
}
ll solve(int n)
{
int len=;
while(n){
bit[len++]=n%;
n/=;
}
return dfs(len-,,).sqsum;
}
int main()
{
init();
int T;
scanf("%d",&T);
while(T--)
{
memset(dp,-,sizeof(dp));
scanf("%d%d%d",&l,&r,&k);
printf("%lld\n",(solve(r)-solve(l-)+MOD)%MOD);
}
return ;
}

[swustoj 917] K-lucky-number的更多相关文章

  1. 枚举 + 进制转换 --- hdu 4937 Lucky Number

    Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

  2. HDOJ 4937 Lucky Number

    当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Numb ...

  3. CF1478-B. Nezzar and Lucky Number

    CF1478-B. Nezzar and Lucky Number 题意: 题目给出一个数字\(d(1\leq d \leq 9)\)代表某个人最喜欢的数字. 题目定义了幸运数字,它的含义为:若一个数 ...

  4. SCU3502 The Almost Lucky Number

    Description A lucky number is a number whose decimal representation contains only the digits \(4\) a ...

  5. 题目1380:lucky number

    转载请注明文本链接 http://blog.csdn.net/yangnanhai93/article/details/40441709 题目链接地址:http://ac.jobdu.com/prob ...

  6. HDU 3346 Lucky Number

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...

  7. 九度oj 题目1380:lucky number

    题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...

  8. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)

    A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. ZOJ 3233 Lucky Number

    Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...

  10. B - Nearly Lucky Number

    Problem description Petya loves lucky numbers. We all know that lucky numbers are the positive integ ...

随机推荐

  1. Linux分类笔记(一)-权限管理

    Linux分类笔记(一) 权限管理 普通权限 文件的普通权限 对一个普通的文件使用ls -ll命令后,看到下面的输出内容   而对于文件权限中的每一位,又分别代表了以下的意思 文件类型又有以下几类: ...

  2. 1010. Radix (25)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  3. windows 与fedora时间差

    windows 默认BIOS时间当前时间UTC+时区, 按北京时间时区,就是要加8个小时. Linux默认BIOS时间是UTC时间,所以同一机子上装WINDOWS与LINUX时间上会差8个小时.这问题 ...

  4. 使用泛型 类型“System.Collections.Generic.IEnumerator<T>”需要 1 个类型参数

    解决办法:添加 using System.Collections:命名空间

  5. Hadoop学习---安装部署

    hadoop框架 Hadoop使用主/从(Master/Slave)架构,主要角色有NameNode,DataNode,secondary NameNode,JobTracker,TaskTracke ...

  6. IIS7 无法访问请求的页面,因为该页的相关配置数据无效

    HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. 解决方案: C:\Windows\Microsoft.NET\Frame ...

  7. [SQL SERVER系列]之常用函数和开窗函数介绍及实例

    本文主要介绍SQL SERVER数据库中一些常用的系统函数及其SQL SERVER 2005以上支持的开窗函数. 1.常用函数 --从字符串右边截取指定字符数 select RIGHT('HELLO' ...

  8. js原生removeclass方法

    //如果列表中有存在给定的值就删除 // function removeClass(ele,txt){ // var str = ele.className, // ary = str.split(/ ...

  9. [转载]MongoDB设置访问权限、设置用户

    MongoDB已经使用很长一段时间了,基于MongoDB的数据存储也一直没有使用到权限访问(MongoDB默认设置为无权限访问限制),今天特地花了一点时间研究了一下,研究成果如下: 注:研究成果基于W ...

  10. spoj 237

    好牛的题  哈哈 #include <cstdio> #include <algorithm> #define S(n) scanf("%d",&n ...