[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 ...
随机推荐
- WPF中Image控件绑定到自定义类属性
首先我们定义一个Student类,有ID,Name,Photo(保存图片路径). using System; using System.Collections.Generic; using Syste ...
- SQLite3中自增主键
SQLite清空表并将自增列归零 SQL标准中有TRUNCATE TABLE语句,用来清空表的所有内容. 但SQLite不支持这个语句.在SQLite中直接使用 DELETE FROM TableNa ...
- Oracle查看用户所在表空间
查看当前用户所在表空间 select username,default_tablespace from user_users; 修改用户默认表空间 alter user 用户名 default tab ...
- 编辑器&IDE中适合程序员的字体
adobe的免费字体 source Code Pro
- 制作输入框(Input)
怎样判断是否应当使用输入框 输入框,就是用户可以自由输入文本的地方.当需要判断是否需要使用输入框时,可以遵循一条原则:凡是需要用户自主输入文本的地方,几乎都必须使用输入框. 输入框的常见用法:输入登录 ...
- Nhibernate 一对一关系映射(主键映射)
参考:点击这里 妈的,搞了一天了,终于可以了,现在总结下,以防下次再出现这样痛苦的问题了,有两个表:user(用户)和Blog(设置表),它们之间的关系正如我所说的是一对一的关系.现在我们来映射这两个 ...
- PlayerPrefs存储数据在本地的存储位置
PlayerPrefs存储数据时,其在windows的存储路径是注册表: HKEY_CURRENT_USER Software CompanyName ProjectName 其中的CompanyNa ...
- struts2+hibernate-jpa+Spring+maven 整合(2)
1.修改pom.xml 1. 添加 slf4j-api <dependency> <groupId>org.slf4j</groupId> <artifac ...
- c++ 字符串工具类
#include <string> #include "util.h" namespace strtool{ std::string trim(const std::s ...
- ActivePython2.7 +Firefly1.2.2+WIN7服务器搭建过程(已通过)
原地址:http://www.9miao.com/question-15-54027.html 1.ActivePython2.7 版本(内部已经包含easy_install,pywin32)2.所需 ...