[swustoj 917] K-lucky-number
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的更多相关文章
- 枚举 + 进制转换 --- hdu 4937 Lucky Number
Lucky Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- HDOJ 4937 Lucky Number
当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Numb ...
- CF1478-B. Nezzar and Lucky Number
CF1478-B. Nezzar and Lucky Number 题意: 题目给出一个数字\(d(1\leq d \leq 9)\)代表某个人最喜欢的数字. 题目定义了幸运数字,它的含义为:若一个数 ...
- SCU3502 The Almost Lucky Number
Description A lucky number is a number whose decimal representation contains only the digits \(4\) a ...
- 题目1380:lucky number
转载请注明文本链接 http://blog.csdn.net/yangnanhai93/article/details/40441709 题目链接地址:http://ac.jobdu.com/prob ...
- HDU 3346 Lucky Number
水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...
- 九度oj 题目1380:lucky number
题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...
- 『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 ...
- ZOJ 3233 Lucky Number
Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
- B - Nearly Lucky Number
Problem description Petya loves lucky numbers. We all know that lucky numbers are the positive integ ...
随机推荐
- windows 与fedora时间差
windows 默认BIOS时间当前时间UTC+时区, 按北京时间时区,就是要加8个小时. Linux默认BIOS时间是UTC时间,所以同一机子上装WINDOWS与LINUX时间上会差8个小时.这问题 ...
- 图像处理-07-图像的轮廓提取-Robert算子
图像的轮廓提取-Robert算子 图像的边缘:周围像素灰度有阶跃变化或“屋顶”变化的那些像素的集合,边缘广泛存在于物体与背景之间.物体与物体之间,基元与基元之间,是图像分割的重要依据. 物体的边缘是由 ...
- EXTJS 4.2 资料 控件之checkboxgroup的用法(静态数据)
1.页面 1.1点击‘横幅’,需要动态显示隐藏文本框 { xtype: 'fieldset', title: '指定附加图&横幅设置', collapsible: true, items: [ ...
- SharpDeveloeper开发ASP.NET MVC汗流浃背
今天好不容易休息了一天,上网狂了一圈,突然想起了以前的一个轻量级的开发工具"SharpDeveloper",于是就下载试着来开发一下ASP.NET,但是老魏没有想到的是,虽然官方提 ...
- Lua基础之Function
概述:1.定义和调用 2.多返回值3.可变参数 原文地址 http://blog.csdn.net/dingkun520wy/article/details/50275387 1.定义和调用 函数,在 ...
- Contest2037 - CSU Monthly 2013 Oct(中南大学2013年10月月赛水题部分题解)
Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题 ...
- redis 在windows 上的安装与使用
1.redis-windows 最近在做一个抢拍模块,由于过于平凡的insert与update I/O受不了,故只好把东西放内存里,等拍卖结束了,在写入磁盘. 至于为什么要用window呢? 因为服务 ...
- 基于注解风格的Spring-MVC的拦截器
基于注解风格的Spring-MVC的拦截器 Spring-MVC如何使用拦截器,官方文档只给出了非注解风格的例子.那么基于注解风格如何使用拦截器呢? 基于注解基本上有2个可使用的定义类,分别是Defa ...
- Binary search for the first element greater than target
We all know how to search through an array for an element whose value equals the target value, but h ...
- [转载]ASP.NET MVC URL重写与优化(进阶篇)-继承RouteBase玩转URL
引言-- 在初级篇中,我们介绍了如何利用基于ASP.NET MVC的Web程序中的Global文件来简单的重写路由.也介绍了它本身的局限性-依赖于路由信息中的键值对: 如果键值对中没有的值,我们无法将 ...