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. C语言:通过指针对字符串进行拼接

    // //  main.c //  Pointer_stringcat // //  Created by ma c on 15/8/2. //  Copyright (c) 2015年 bjsxt. ...

  2. 我所遭遇过的游戏中间件--FlashOcx

    使用Flash做游戏界面的另一种方式是通过Abode提供flash.ocx处理Flash界面.将Flash图像通过GDI绘制出来后,再将图像数据拷贝到一个D3D的纹理结构中,最后由引擎的D3D接口进行 ...

  3. IE6与CSS样式兼容问题汇总

    1.PNG半透明图片的问题 虽然可以通过JS等方式解决,但依然存在载入速度等问题,所以,这个上能不要用还是尽量不要用.以达到网站最大优化. 2.IE6下的圆角 IE6不支持CSS3的圆角属性,比较好的 ...

  4. JS 中数组字符串索引和数值索引研究

    先来看一个问题: var array = []; array["a"] = "hello"; array["b"] = "worl ...

  5. 一个常见下拉菜单的样式:一体化小三角(纯css手写解决)

    类似下拉菜单2个一体化小三角,习惯上用字体图标加jQuery处理,比较方便,但是下面纯css手写解决方式,效果也还不错,对CSS知识也是一个比较好的孔固. 小三角用了2种不同处理方式:1.利用bord ...

  6. 本地主机DNS劫持演示及防范

    劫持演示                                                                                      如果要进行DNS劫持 ...

  7. 为Ubuntu 安装Transmission 2.90

    Transmission 是 Ubuntu 的默认 BitTorrent 客户端,近期发布了最新的 Transmission 2.90 版本,目前已经可通过 PPA 为 Ubuntu 15.10.Ub ...

  8. python 两个队列进行对比

    python 两个队列进行对比 list01 = [1,2,3,4] list02 = [1,3,5] for i01 in list01: is_in_02 = False for i02 in l ...

  9. C#.NET常见问题(FAQ)-interface接口如何理解

    个人把interface理解为一种比较特殊的判断技巧,不是常规的变量类型比如判断字符串,判断数组,而是判断类的实例是否拥有某些属性或者方法(比如有十个女的穿一样的衣服,头上盖住,让新郎去猜哪一个是他的 ...

  10. POJ 1436 Horizontally Visible Segments (线段树&#183;区间染色)

    题意   在坐标系中有n条平行于y轴的线段  当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交  就视为它们是可见的  问有多少组三条线段两两相互可见 先把全部线段存下来  并按x ...