Good Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 673    Accepted Submission(s): 242

Problem Description
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number. You are required to count the number of good numbers in the range from A to B, inclusive.
 
Input
The first line has a number T (T <= 10000) , indicating the number of test cases. Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
 
Output
For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
 
Sample Input
2 1 10 1 20
 
Sample Output
Case #1: 0 Case #2: 1

Hint

The answer maybe very large, we recommend you to use long long instead of int.

 
Source
 找规律......
代码:
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define LL _int64
#include<algorithm>
using namespace std;
LL cal(LL n)
{
LL num,i,j,ans,sum;
num=n/100;
ans=num*10;
for(i=num*100;i<=n;i++)
{
j=i;
sum=0;
while(j)
{
sum+=j%10; //将各个位相加
j/=10;
}
if(sum%10==0)
ans++;
}
return ans;
}
void Init()
{
LL l,r;
static int count=1;
scanf("%I64d%I64d",&l,&r);
LL temp=cal(r)-cal(l-1);
printf("Case #%d: %I64d\n",count++,temp);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
Init();
}
return 0;
}

HDUOJ----Good Numbers的更多相关文章

  1. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  2. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  3. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  4. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  5. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  6. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  7. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  8. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  9. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  10. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

随机推荐

  1. 仿LOL项目开发第七天

    仿LOL项目开发第七天 by 草帽 不知不觉已经写到了第七篇这种类型的博客,但是回过头看看之前写的,发现都只能我自己能看懂. 我相信在看的童鞋云里雾里的,因为我基本上没怎么详细讲一个脚本怎么用?但是你 ...

  2. c++反汇编与逆向分析 小结

    第一章  熟悉工作环境和相关工具 1.1 熟悉OllyDBG  操作技巧 1.2 反汇编静态分析工具 IDA(最专业的逆向工具)     快捷键    功能     Enter     跟进函数实现 ...

  3. react random key generator;react如何产生随机不重复的key

    1.<div key={+new Date() + Math.random()}> 2.使用数组的索引 3.使用uuid:https://www.npmjs.com/package/uui ...

  4. 第九章 Redis过期策略

    注:本文主要参考自<Redis设计与实现> 1.设置过期时间 expire key time(以秒为单位)--这是最常用的方式 setex(String key, int seconds, ...

  5. RAID5工作原理介绍

    RAID 5是一种存储性能.数据安全和存储成本兼顾的存储解决方案.以四个硬盘组成的RAID 5为例,其数据存储方式如图4所示:图中,P0为D0,D1和D2的奇偶校验信息,P1为D3,D4,D5的奇偶校 ...

  6. Discuz常见大问题-如何允许用户插入视频-如何自己在页面中插入视频

    从视频的下面分享中获取html代码 然后粘贴到你创建页面的指定位置(注意从优酷复制的视频宽度和高度可能比较小,你可以自己调整,或者占据100%) 最终的实现效果

  7. 如何安装Tomcat

    1 请确认已经安装了JRE或JDK并配置好了环境变量,关于如何配置环境变量,参考我的另一篇文章"WIN7如何配置java环境变量,运行环境.doc" 2 用记事本打开bin目录下的 ...

  8. 批量合并GDB

    在实际操作中,经常对数据库文件进行合并.裁切等.如果遇到gdb比较多,要素层比较多,而且还存在数据集.虽然ArcGIS中的批量处理的功能,但填写参数过程也比较麻烦,如果一次性处理过多,程序容易停止工作 ...

  9. Android 的一些提示框

    1.在测试时,如何实现一个提示 可以使用 Toast.makeText(this, "这是一个提示", Toast.LENGTH_SHORT).show(); //从资源文件str ...

  10. 使用JSP实现输出(web基础学习笔记二)

    Jsp:Java Server Page 服务器端的Java页面,动态网页技术 jsp注释 显式注释:这种注释客户端是允许看见的;<!--html注释--> 隐式注释:这种注释客户端是看不 ...