Poor Hanamichi
Poor Hanamichi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
A integer X can be represented in decimal as:
X=An×10n+An−1×10n−1+…+A2×102+A1×101+A0
The odd dights are A1,A3,A5… and A0,A2,A4… are even digits.
Hanamichi comes up with a solution, He notices that:
102k+1 mod 11 = -1 (or 10), 102k mod 11 = 1,
So X mod 11
= (An×10n+An−1×10n−1+…+A2×102+A1×101+A0)mod11
= An×(−1)n+An−1×(−1)n−1+…+A2−A1+A0
= sum_of_even_digits – sum_of_odd_digits
So he claimed that the answer is the number of numbers X in the range which satisfy the function: X mod 11 = 3. He calculate the answer in this way :
Answer = (r + 8) / 11 – (l – 1 + 8) / 11.
Rukaw heard of Hanamichi’s solution from you and he proved there is something wrong with Hanamichi’s solution. So he decided to change the test data so that Hanamichi’s solution can not pass any single test. And he asks you to do that for him.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
LL lt,rt;
LL test(LL x){
int d[],i = ,j,sum = ;
LL y = x;
while(x){d[i++] = x%; x /= ;}
for(j = ; j < i; j++){
if(j&)sum -= d[j];
else sum += d[j];
}
if(sum != ) return y;
return -;
}
int main() {
int t;
LL tst;
scanf("%d",&t);
while(t--){
scanf("%I64d %I64d",<,&rt);
bool flag = false;
for(LL i = lt/+; i*+ <= rt; i++){
tst = test(i*+);
if(tst > ) {flag = true;break;}
}
if(flag) printf("%I64d\n",tst);
else puts("-1");
}
return ;
}
最新文章
- call_user_func()的参数不能为引用传递 自定义替代方法
- 第3章 Linux常用命令(6)_关机重启命令
- java中使用队列:java.util.Queue (转)
- raspberry pi 如何汉化显示中文
- XBox360-双光盘游戏自制GOD
- 为网站加入Drupal星球制作RSS订阅源
- 实战开发中UI资源制作标准
- 从 mian 函数开始一步一步分析 nginx 执行流程(三)
- CTime,Systemtime的比较还有转换成日期格式。
- shell中的declare命令
- sql从某不连续的数字中将其分段并找出缺失的数字并分段
- 设计模式16:迭代模式(Iterator)
- Chrome浏览器扩展开发系列之十八:扩展的软件国际化chrome.i18n API
- Work 3(工作类) (2017.07.01)
- 计蒜客NOIP模拟赛(2) D2T1 劫富济贫
- Spring Cloud Alibaba基础教程:使用Sentinel实现接口限流
- JDK的动态代理-----为接口进行代理
- 论文阅读笔记三十六:Mask R-CNN(CVPR2017)
- 杨其菊201771010134《面向对象程序设计(java)》第六周学习总结
- gulp入门实践
热门文章
- P2746 [USACO5.3]校园网Network of Schools(Tarjan)
- python自动化测试学习笔记-9测试框架
- 2017杭电多校第六场1011Classes
- 使用mysqldump导出数据库(表)
- EasyUI系列学习(十)-Tabs(选项卡)
- Unity笔记(2)自学第一天
- Python批量生成用户名
- PHP开发心得四
- SpringBoot+Mybatis 自动创建数据表(适用mysql)
- chr()返回值是当前整数对应的 ASCII 字符。