FZU Problem 2125 简单的等式

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

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<iostream>
 7 #define LL long long
 8 using namespace std;
 9 
10 int main() {
11     //freopen("in.txt","r",stdin);
12     __int64 t,n,m,ans;
13     scanf("%I64d",&t);
14     while(t--) {
15         scanf("%I64d%I64d",&n,&m);
16         __int64 x = sqrt(n*1.0);
17         ans = -1;
18         while(x) {
19             if(n%x==0) {
20                 __int64 sum = 0,tem = x;
21                 while(tem) {
22                     sum+=tem%m;
23                     tem/=m;
24                 }
25                 if(sum == n/x-x) {
26                     ans = x;
27                 }
28             }
29             if(n/x-x>112)
30                 break;
31             x--;
32         }
33         printf("%I64d\n",ans);
34     }
35     return 0;
36 }
View Code

 

  

转载于:https://www.cnblogs.com/ITUPC/p/5338774.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值