2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest E. Equal Digits
2 seconds
256 megabytes
standard input
standard output
For the given integer N and digit D, find the minimal integer K ≥ 2 such that the representation of N in the positional numeral system with base K contains the maximum possible consecutive number of digits D at the end.
The input contains two integers N and D (0 ≤ N ≤ 1015, 0 ≤ D ≤ 9).
Output two integers: K, the answer to the problem, and R, the the number of consecutive digits D at the end of the representation of Nin the positional numeral system with base K.
3 1
2 2
29 9
10 1
0 4
2 0
90 1
89 2
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
using namespace std;
typedef long long LL;
typedef double DB;
#define Rep(i, n) for(int i = (0); i < (n); i++)
#define Repn(i, n) for(int i = (n)-1; i >= 0; i--)
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, t, s) for(int i = (t); i >= (s); i--)
#define rep(i, s, t) for(int i = (s); i < (t); i++)
#define repn(i, s, t) for(int i = (s)-1; i >= (t); i--)
#define MIT (2147483647)
#define MLL (1000000000000000000LL)
#define INF (1000000001)
#define mk make_pair
#define ft first
#define sd second
#define clr(x, y) (memset(x, y, sizeof(x)))
#define sqr(x) ((x)*(x))
#define sz(x) ((int) (x).size())
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back template<class T>
inline T Getint()
{
char Ch = ' ';
T Ret = ;
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Ret;
} LL n;
int d;
vector<LL> Factor; inline void Input()
{
cin >> n >> d;
} inline void Solve()
{
if(n == d)
{
if(n <= ) puts("2 1");
else cout << n + 1LL << "" << endl;
return;
}
if(n < d)
{
puts("2 0");
return;
} LL T = n - d;
for(LL i = ; i * i <= T; i++)
if(T % i == )
{
if(i > d) Factor.pub(i);
if(T / i > d) Factor.pub(T / i);
} LL R = , k = ;
int Length = sz(Factor), Cnt;
Rep(i, Length)
{
if(Factor[i] == ) continue; T = n, Cnt = ;
while(T % Factor[i] == d)
T /= Factor[i], Cnt++; if(Cnt > R) R = Cnt, k = Factor[i];
else if(Cnt == R) k = min(k, Factor[i]);
} cout << k << ' ' << R << endl;
} int main() {
//freopen("E.in", "r", stdin);
Input();
Solve();
return ;
}
2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest E. Equal Digits的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic(Kruskal思想)
2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic 题意:有一张图,第i个点被占领需要ai个兵,而每个兵传送至该 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉
Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题
Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...
- 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator
题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
随机推荐
- Java RSA 密钥生成工具
MAC openssl: RSA加解密 第一条命令是生成密钥长度为1024的密钥: 第二条命令是从中生成公钥: 第三条命令是使用pkcs8编码密钥为私钥 http://blog.csdn.net/ch ...
- Android Hybrid开发
参考:谈谈Android App混合开发 Html 5和Native的交互 WebView 本来就支持js和Java相互调用,你只需要开启 WebView 的JavaScript脚本执行, 然后通过代 ...
- C++异常层次结构图
- iOS - 定制多样式二维码
二维码/条形码是按照某种特定的几何图形按一定规律在平台(一维/二维方向上)分布的黑白相间的图形纪录符号信息.使用若干个与二进制对应的几何形体来表示文字数值信息. 最常见的二维码功能包括信息获取.网 ...
- nfs 是Network File System 网络文件系统
NFS的基本原刚是容许不同的客户端及服务通过一组PRC分享相同的文件系统,它是独立于操作系统,容许不同硬件及操作系统的系统共同进行文件的分享.NFS在文件传送过程中依赖于RPC协议.远程过程调用Rem ...
- windows 远程桌面命令 mstsc
win+R------>mstsc: 弹出: 目标机必开远程
- map find 是线程安全的吗
测试环境gcc4.8.2 iterator find ( const key_type& k ); const_iterator find ( const key_type& ...
- Delphi强制类型转化和类型约定
强制类型转换时一种技术,通过它能够使编译器把一种类型的变量当做另一种类型. 由于Pascal有定义新类型的功能,因此编译器在调用一个函数时候对形参和实参类型匹配的检查是非常严格的.因此为了能够通过编译 ...
- Python 的三目运算
其他语言:php 判定条件?为真时的结果:为假时的结果 $a=88 $b=99 $res = $a>$b?$a>$b 搞笑的Python:令人意想不到的语法形式 true_value if ...
- 攻城狮在路上(壹) Hibernate(十三)--- Hibernate的检索方式(上)
Hibernate提供了以下几种检索对象的方式: A.导航对象图检索方式. B.OID检索方式.Session.get() load(); C.HQL检索方式.Query. D.QBC检索方式.Que ...