2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest —— E. Equal Digits
来源:互联网 发布:淘宝交易量查询 编辑:程序博客网 时间:2024/04/29 16:10
E. Equal Digits
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputFor the given integer N and digit D, find the minimal integer K ≥ 2 such that the representation ofN in the positional numeral system with baseK contains the maximum possible consecutive number of digitsD at the end.
Input
The input contains two integers N and D (0 ≤ N ≤ 1015,0 ≤ D ≤ 9).
Output
Output two integers: K, the answer to the problem, andR, the the number of consecutive digitsD at the end of the representation of N in the positional numeral system with baseK.
Sample test(s)
Input
3 1
Output
2 2
Input
29 9
Output
10 1
Input
0 4
Output
2 0
Input
90 1
Output
89 2
题意:
给出n 和 d , 要求得到用k 进制得到n,最后一个数要求为d,求出从后数d 的数量,要求数量最多是k 尽可能小。
思路:
要使n - d 用k 进制表示出,所以求出n-d 的因子,暴力枚举得到最大答案。
特殊情况是:n== d 和n< d
CODE:
#include <iostream>#include <cstdio>#include <vector>#include <cmath>using namespace std;typedef long long ll;vector<ll> v;ll n, d;void work(ll nn){ for(ll i = 1; i * i <= nn; ++i){ if(nn%i == 0){ if(i > d) v.push_back(i); if((nn/i) > d && i*i != nn) v.push_back(nn/i); } }}int main(){ //freopen("in", "r", stdin); while(~scanf("%I64d %I64d", &n, &d)){ if(n == d){ if(n <= 1) printf("2 1\n"); else printf("%I64d 1\n",n + 1); continue; } if(n < d){ printf("2 0\n"); continue; } v.clear(); work(n - d); ll r = 0, k = 2; for(ll i = 0; i < v.size(); ++i){ ll n1 = n, s = 0; if(v[i] > 1){ while(n1){ if(n1 % v[i] != d) break; else{ s++; n1 = n1/v[i]; } } if(s > r){ r = s; k = v[i]; } if(s == r && v[i] < k){ k = v[i]; } } } printf("%I64d %I64d\n", k, r); } return 0;}
0 0
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest —— E. Equal Digits
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest A
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest K
- D. Do it Right!(2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest )
- F. Friends(2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest )
- 2012-2013 ACM-ICPC, NEERC, Moscow Subregional Contest
- 2013-2014 ACM-ICPC, NEERC, Moscow Subregional Contest (2013区域赛练习)
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest C. Colder-Hotter
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest A题:Anagrams [打表/规律题]
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest C题:Colder-Hotter [三分/交互题]
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest D题:Delay Time [暴力题]
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest H题: Hashing [基础DP]
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest I题:Illegal or Not? [暴力题]
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest K题:King's Rout [topo排序]
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest K. King’s Rout(拓扑排序)
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest (C. Colder-Hotter)(二维猜数字)
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest(K. King's Rout)(拓扑排序)
- Java内存泄露原因详解
- 对一个简单数学问题的浮想
- 水的效果
- 微信平台接口绑定总是提示超时 解决方法
- 基于ARM+Linux的直流伺服控制系统设计
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest —— E. Equal Digits
- 118. Digital Root
- 使用Nginx搭建RTMP服务器
- Linux进程管理
- 什么是Cocos2D?
- POJ2151Check the difficulty of problems 概率DP
- 小马哥-- 中国移动定制版4G。 高仿oppo 4G版等机型拆机图 开机图 谨防假冒
- Ubuntu 使用 heirloom-mail 调用外部邮箱 SMTP 服务器发送邮件
- 使用同步适配器(sync adapter)传输数据