FZU Problem 2125 简单的等式

时间:2023-03-09 00:46:59
FZU Problem 2125 简单的等式

思路:x绝对小于根号n,再由s(x,m)可以缩小范围。1e9十六进制大约算出每位和相加100左右。这种题直接判断范围再暴力。

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#define LL long long
using namespace std; int main() {
//freopen("in.txt","r",stdin);
__int64 t,n,m,ans;
scanf("%I64d",&t);
while(t--) {
scanf("%I64d%I64d",&n,&m);
__int64 x = sqrt(n*1.0);
ans = -;
while(x) {
if(n%x==) {
__int64 sum = ,tem = x;
while(tem) {
sum+=tem%m;
tem/=m;
}
if(sum == n/x-x) {
ans = x;
}
}
if(n/x-x>)
break;
x--;
}
printf("%I64d\n",ans);
}
return ;
}