E. Equal Digits
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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, and R, the the number of consecutive digits D at the end of the representation of Nin the positional numeral system with base K.

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在k进制下,尾部的d的数量最大。
分析:
显然答案是一个正整数,因为我们可以取k=n-d进制。
那么,因为至少为1,则k必定整除于n-d
那么将n-d分解,将其因数全部拿出来。
暴力更新答案即可。
因数个数在根号级别,暴力计算复杂度在log级别,不会超时。
 #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的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 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个兵,而每个兵传送至该 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...

  8. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  9. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

随机推荐

  1. poj1456(贪心+并查集)

    题目链接: http://poj.org/problem?id=1456 题意: 有n个商品, 已知每个商品的价格和销售截止日期, 每销售一件商品需要花费一天, 即一天只能销售一件商品, 问最多能买多 ...

  2. 求n阶方阵的值(递归)

    若有n*n阶行列式A,则: |A|=A[1][1]*M[1][1]+A[1][2]*M[1][2]+...A[1][n]*M[1][n]:其中M[1][i] 表示原矩阵元素A[1][i]的代数余子式: ...

  3. mysql 查看用户的权限

    show grants for 'username'@'%';

  4. MangoDB的C#Driver驱动简单例子

    以下是本人学习C#Driver驱动简单的学习例子.GridFS的增删查操作 和 表的增删查改操作. public class MongoServerHelper { public static str ...

  5. 让那些为Webkit优化的网站也能适配IE10(转载)

    转载地址:http://www.w3cplus.com/css3/adapting-your-webkit-optimized-site-for-internet-explorer-10.html 特 ...

  6. markdown编辑器使用建议

    markdown在线编辑器: https://stackedit.io/editorhttp://dillinger.io/ windows 下建议使用 MarkdownPad linux 下建议使用 ...

  7. Delphi中exit、break、continue等跳出操作的区别

    Delphi中表示跳出的有break,continue,abort,exit,halt,runerror等 1.break 强制退出最近的一层循环(注意:只能放在循环里:而且是只能跳出最近的一层循环) ...

  8. MDX语法之排序函数Order

    使用场景: 排列指定集的成员,可以选择保留或打乱原有的层次结构. 语法: Numeric expression syntax Order(Set_Expression, Numeric_Express ...

  9. 项目管理10000 hours – 瞎扯谈系列

    本系列会 zz 网上现有的文章,套句经典的话就是死磕自己,娱乐大众. 项目能否按时完成是项目管理的重要目标,将会面临的问题有团队的稳定性,冲突,会议以及压力. 团队中适度的人员流动是可以理解的,如何减 ...

  10. RTCP资料详解

    转自:http://www.360doc.com/content/13/0606/10/1317564_290865866.shtml RTCP RTCP协议将控制包周期发送给所有连接者,应用与数据包 ...