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 ...
随机推荐
- windows server 2008镜像重启后密码变为默认密码的问题的解决方案
1. cmd中执行regedit,打开注册表: 修改HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cloudbase Solusions\Cloudbase-Init ...
- zoj1873 Let it Bead
思路:polya裸题,如果是旋转,对于旋转i格的循环节长度len=lcm(i,n)/i,个数就是n/len=gcd(i,n):如果是翻转,奇数个点对称轴就是一个点一条边,那么循环节个数即n/2+1, ...
- What are TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR (etc.)?
转自: http://www.codeproject.com/Articles/76252/What-are-TCHAR-WCHAR-LPSTR-LPWSTR-LPCTSTR-etc 解释的超详细!! ...
- hibernate符合主键
当有符合主键时,一方与多方的复合主键顺序必须一致: <set> <key> <column name="A" /> <column nam ...
- 【Android】 Sqlite3 not found
调试机没有sqlite3命令文件 导入即可 sqlite3 http://pan.baidu.com/s/1bohTMiz //(使用老版sqlite3需要导入libncurses.so文件至/sys ...
- 破解https和https原理
http://blog.csdn.net/cch5487614/article/details/6364711 http://www.jb51.net/network/68135.html
- js传带参数的函数
字符串: setTimeout('pageScroll(4)',100);
- arm-linux-gcc编译器定义寄存器变量
uboot代码中有这么一句话“#define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("r8")”, ...
- 7个热门开源PHP框架
PHP(Hypertext Preprocessor)是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点.虽然有很多其它可供选择的Web开发语言,像:ASP 和Ruby,但是PHP是目 ...
- leetcode第七题Reverse Integer (java)
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, retu ...