当前位置:网站首页>50. pow (x, n) - fast power
50. pow (x, n) - fast power
2022-06-25 07:52:00 【Mr Gao】
50. Pow(x, n)
Realization pow(x, n) , Computation x The integer of n Power function ( namely ,xn ).
Example 1:
Input :x = 2.00000, n = 10
Output :1024.00000
Example 2:
Input :x = 2.10000, n = 3
Output :9.26100
Example 3:
Input :x = 2.00000, n = -2
Output :0.25000
explain :2-2 = 1/22 = 1/4 = 0.25
The solution code is as follows , Fast power , Usually with a 2 A fast product algorithm with base :
double myPow(double x, int n){
if (n == 0)
return 1; // Recursive export
if (n == 1)
return x; // Recursive export
// if (n < 0)
// return 1 / myPow(x, -n); // here n Will cross the border
if (n == -1)
return 1 / x; // Just define recursive exits
if (n % 2 != 0)
return x * myPow(x, n - 1);
else
return myPow(x * x, n / 2);
}
边栏推荐
猜你喜欢

(tool class) use SecureCRT as the communication medium

机器学习笔记 - 时间序列的线性回归

Share the process requirements for single-layer flexible circuit board

el-input实现尾部加字

How to use ad wiring for PCB design?

环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用

Manufacturing process of PCB 2021-10-11

差点被这波Handler 面试连环炮带走~
![[distillation] pointdistiller: structured knowledge distillationwards efficient and compact 3D detection](/img/5c/ad42474a363c33ecc0e01890b65bbf.png)
[distillation] pointdistiller: structured knowledge distillationwards efficient and compact 3D detection

Modular programming of LCD1602 LCD controlled by single chip microcomputer
随机推荐
What are the benefits of reserving process edges for PCB production? 2021-10-25
2160. 拆分数位后四位数字的最小和
[little knowledge] PCB proofing process
Bicubic difference
Insert and sort the linked list [dummy unified operation + broken chain core - passive node]
Vscode is good, but I won't use it again
权限、认证系统相关名词概念
Force deduction 76 questions, minimum covering string
NSIS 静默安装vs2013运行时
MySQL简单权限管理
Invalid Navicat scheduled task
Usememo simulation usecallback
Pcb|about FPC reinforcement type
VSCode很好,但我以后不会再用了
Modular programming of LCD1602 LCD controlled by single chip microcomputer
Pytorch遇到的坑:为什么模型训练时,L1loss损失无法下降?
useMemo模拟useCallback
神经网络与深度学习-3- 机器学习简单示例-PyTorch
The method of judging whether triode can amplify AC signal
Analysis and utilization of Microsoft Office Word remote command execution vulnerability (cve-2022-30190)