数位dp.

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} int dp[][],t[]; void pre()
{
memset(dp,,sizeof dp); dp[][]=; // get时要× dp[][]=; // 0 1 2 4 5 6 7 9
dp[][]=; //
dp[][]=; // for(int i=;i<=;i++)
{
dp[i][]=*dp[i-][];
dp[i][]=dp[i-][]+*dp[i-][];
dp[i][]=dp[i-][]+*dp[i-][];
}
} int get(int x)
{
int sz=; while(x) t[sz++]=x%, x=x/;
for(int i=sz;i>=;i--) t[i]=t[i-]; int res=; bool san=,ba=; for(int i=sz;i>=;i--)
{
//该位可以放 0 1 2 3 4....t[i]-1
if(san==&&ba==)
{
//放 0 1 2
if(t[i]<=) res=res+
dp[i-][]*t[i]+
dp[i-][]*t[i]; //放 0 1 2 3 4 5 6 7
else if(t[i]<=) res=res+
dp[i-][]+
dp[i-][]*t[i]+
dp[i-][]*(t[i]-); //放 0 1 2 3 4 5 6 7 8
else if(t[i]==) res=res+
dp[i-][]+
dp[i-][]+
dp[i-][]*(t[i]-)+
dp[i-][]*(t[i]-); if(t[i]==) san=; if(t[i]==) ba=;
if(san==&&ba==) return res;
continue;
} int id,limit; if(san==) id=,limit=; else id=,limit=; //放 0 1 2 .. limit-1
if(t[i]<=limit) res=res+
dp[i-][]*t[i]+
dp[i-][id]*t[i]; //放 0 1 2 .. t[i]-1
else res=res+
dp[i-][]*(t[i]-)+
dp[i-][id]*(t[i]-); if(t[i]==) san=; if(t[i]==) ba=;
if(san==&&ba==) return res;
} return res;
} int main()
{
pre(); int T,L,R;
scanf("%d",&T); while(T--)
{
scanf("%d%d",&L,&R);
printf("%d\n",get(R+)-get(L));
}
return ;
}

ACdream 1064 完美数的更多相关文章

  1. 华为OJ平台——完美数

    import java.util.Scanner; /** * * 完全数(Perfect number),又称完美数或完备数,是一些特殊的自然数. * 它所有的真因子(即除了自身以外的约数)的和(即 ...

  2. SDUT 1220 完美数

    完美数 Time Limit: 1000ms   Memory limit: 65536K 题目描述 任何一个自然数的约数中都有1和它本身,我们把小于它本身的因数叫做这个自然数的真约数. 如6的所有真 ...

  3. 1000以内完全数(完美数)获取实现---基于python

    """题目: 如果一个数恰好等于它的因子之和,则称该数为"完全数" .各个小于它的约数(真约数,列出某数的约数,去掉该数本身,剩下的就是它的真约数)的 ...

  4. [51nod1232]完美数

    如果一个数能够被组成它的各个非0数字整除,则称它是完美数.例如:1-9都是完美数,10,11,12,101都是完美数,但是13就不是完美数(因为13不能被数字3整除). 现在给定正整数x,y,求x和y ...

  5. [Swift]LeetCode507. 完美数 | Perfect Number

    We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...

  6. 51nod 1232 完美数 数位dp

    1232 完美数 题目来源: 胡仁东 基准时间限制:2 秒 空间限制:131072 KB  如果一个数能够被组成它的各个非0数字整除,则称它是完美数.例如:1-9都是完美数,10,11,12,101都 ...

  7. Leetcode 507.完美数

    完美数 对于一个 正整数,如果它和除了它自身以外的所有正因子之和相等,我们称它为"完美数". 给定一个 正整数 n, 如果他是完美数,返回 True,否则返回 False 示例: ...

  8. 507 Perfect Number 完美数

    对于一个 正整数,如果它和除了它自身以外的所有正因子之和相等,我们称它为“完美数”.给定一个 正整数 n, 如果他是完美数,返回 True,否则返回 False示例:输入: 28输出: True解释: ...

  9. Java实现 LeetCode 507 完美数

    507. 完美数 对于一个 正整数,如果它和除了它自身以外的所有正因子之和相等,我们称它为"完美数". 给定一个 整数 n, 如果他是完美数,返回 True,否则返回 False ...

随机推荐

  1. H3 BPM报销流程开发示例

    以报销流程为示例,介绍H3 BPM的流程开发过程. 报销流程的表单效果如下: 审核流程为填写报销申请.主管审核.总监审核(1000以上).出纳付款,显示如下: 步骤一:准备工作 使用管理员账号的登录H ...

  2. Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if expl

    检查你的用户名和密码是否正确 ,以及位置是否正确:

  3. svn 目录设置为 不提交 忽略

    svn 忽略  以下文件 和目录 (不提交) runningtime --选中 tortoiseSVN --unversion and add to ignore list web workspace ...

  4. python学习——DAY1

    日期:20170113 一.个人体会: 零基础学python,是艰辛的,需要付出和坚持. 关于流程图.我最开始画的是从上到下,再从左到右,画了很多重复的内容,单线程的流程图,看起来很容易理解,但是自己 ...

  5. 文档在线预览开源实现方案一:OpenOffice + SwfTools + FlexPaper

    在文档在线预览方面,项目组之前使用的是Microsoft office web apps, 由于该方案需要按照微软License付费,项目经理要我预研一个文档在线预览的开源实现方案.仔细钻入该需求发现 ...

  6. macos上安装wget命令

    首先从Apple Store下载Xcode,然后安装Xcode,接着安装Homebrew包管理,类似于Ubuntu下的apt-get: 终端下输入ruby -e "$(curl -fsSL ...

  7. spring、struts整合

    package com.hanqi.test; public class JISQ { public double add(double a,double b) { return (a+b); } } ...

  8. RedHat9.0下载地址

    RedHat下载:http://archive.download.redhat.com/pub/redhat/linux/9/en/iso/i386/

  9. c:set 存值

    <c:forEach items="${appoint}" var="appoint"> <c:set var="begin&quo ...

  10. 安卓用canvas画曲线图

    1.新建一个常变量类Constant.java package com.rain.db; import android.graphics.Point; public class Constant { ...