Good Numbers
You are required to count the number of good numbers in the range from A to B, inclusive.
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
1 10
1 20
The answer maybe very large, we recommend you to use long long instead of int.
#include<cstdio> __int64 sum(__int64 b)
{
int flag=;
__int64 s=b,sb;
__int64 sum=;
while(s!=)
{
sum+=s%;
s/=;
}
sum=sum-b%;
sum%=;
if(sum== || sum+b%>=) flag=;
else flag=;
sb=b/-flag;
return sb;
} int main()
{
__int64 a,b;
int t,step=,k;
scanf("%d",&t);
while(t--)
{
k=;
scanf("%I64d%I64d",&a,&b);
if(a==) k=;
printf("Case #%d: %I64d\n",step++,sum(b)-sum(a-)+k);
}
return ;
}
数论,找规律
Good Numbers的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [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 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
- [LeetCode] Sum Root to Leaf Numbers 求根到叶节点数字之和
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
随机推荐
- 01_JavaMail_02_Base64加密
[简述] Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一.Base64编码可用于在HTTP环境下传递较长的标识信息.例如,在Java Persistence系统Hibernate中 ...
- IDC机房动力环境设备维护
高低压配电 空调 ...
- Dell Remote Access Controller 添加和配置 DRAC/MC 用户
iDRAC设置 单击“Configuration”(配置)选项卡并选择“Users”(用户). 单击“Username”(用户名)列下的 [Available](可用)添加新用户,或单击“Userna ...
- Qt creator 创建鼠标右键菜单 (不新建类)
界面 步骤 打开你的界面文件并选中你要添加右键的控件,选择“CustomContextMenu” 右键选择“转到槽...” -> customContextMenuRequested 插入下面代 ...
- ActiveMQ基本配置与示例演示
一.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 二.运行ActiveMQ 将apache-activemq-5.11.1-bin.zip解压,由于本系 ...
- NPOI_2.1.3-Excel中设置小数、百分比、货币、日期、科学计数法和金额大写
在操作Excel时候一些特殊值的转换是在所难免的,下面就给出转换方法大同小异,代码如下: HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); ISheet ...
- 《APUE》第三章笔记(3)
文件共享 UNIX系统支持在不同进程中共享打开的文件,首先先用一幅apue的图来介绍一下内核用于I/O文件的数据结构: 如图所见,一个进程都会有一个记录项,记录项中包含有一张打开文件描述符表,每个描述 ...
- DIV+CSS 网页布局之:三列布局
1.宽度自适应三列布局 三列布局的原理和两列布局的原理是一样的,只不过多了一列,只需给宽度自适应两列布局中间再加一列,然后重新计算三列的宽度,就实现了宽度自适应的三列布局. 同样的道理,更多列的布局, ...
- Python 修饰器
描述:对于函数foo,使用修饰器修饰,在执行foo函数的同时统计执行时间.这样其他函数都可以使用此修饰器得到运行时间. (有返回值和没有返回值的函数要用不同的修饰器似乎) (对于有返回值的函数,不确定 ...
- Qt之json解析
Jsoner::Jsoner(QObject *parent) : QObject(parent){ QJsonObject json; json.insert("loginna ...