文章

7

粉丝

387

获赞

7

访问

65.4k

头像
升次方--来一份C++的AC代码,C++手写高精度人永不为奴!
P1535 清华大学2019年机试题
发布于2021年1月13日 02:03
阅读数 11.2k

开根基本上就是FFT乘法+快速幂+二分答案

但是本题确保存在一个正整数a使得a^n=m 即不需要向下取整的操作,所以需要和原本的二分思路有所转换

python代码如下,可以视作一个伪代码

n,m=input().split()
m=int(m)
l=len(n)//m
n=int(n)
x=10**l
a=x
y=10**(l+1)
while True:
    b=n-a**m
    if b>0:
        x=a
        a=(a+y)//2
    elif b<0:
        y=a
        a=(a+x)//2
    else:
        break
print(a)

C++代码如下

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cstdlib>

#include <algorithm>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ull MODD = 998244353;

struct cd {
    double re, im;
    
...
登录查看完整内容


登录后发布评论

1 条评论
飞天老头
2023年4月4日 20:04

600行的代码,吓蒙了...

赞(0)