注意最后一轮要单独求一下 且最后只能有一个root #include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ll long long int #define vi vector<int> #define vii vector< vector<int> > #define PI 3.1415926535897932384626433832795 #define I…
69. Sqrt(x) Total Accepted: 93296 Total Submissions: 368340 Difficulty: Medium 提交网址: https://leetcode.com/problems/sqrtx/ Implement int sqrt(int x). Compute and return the square root of x. 分析: 解法1:牛顿迭代法(牛顿切线法) Newton's Method(牛顿切线法)是由艾萨克·牛顿在<流数法>(M…
二分求幂 int getMi(int a,int b) { ; ) { //当二进制位k位为1时,需要累乘a的2^k次方,然后用ans保存 == ) { ans *= a; } a *= a; b /= ; } return ans; } 快速幂取模运算 公式: 最终版算法: int PowerMod(int a, int b, int c) { ; a = a % c; ) { = = )ans = (ans * a) % c; b = b/; a = (a * a) % c; } retur…