博客
关于我
将一个数开m次方(模板)
阅读量:244 次
发布时间:2019-02-28

本文共 641 字,大约阅读时间需要 2 分钟。

#include 
#include
#include
#include
#include
using namespace std;int fun(int n) { int ans = 0; while (n) { n /= 2; ans++; } return ans;}int main() { int n; int m = 3; scanf("%d", &n); int k = fun(n); // 计算n的二进制位数 int now = n >> ((k - 1) * (m - 1) / m); int last; do { last = now; now = (last * (m - 1) + n / pow(last, m - 1)) / m; } while (now < last); printf("%d\n", last); return 0;}

以上代码展示了一个读取整数n并计算其开m次根的程序,其中m设定为3。程序首先通过fun函数计算n的二进制位数k。然后通过迭代方法逐步逼近n的开m次根。最后输出近似值。

转载地址:http://enqp.baihongyu.com/

你可能感兴趣的文章
Python 八大排序算法合集
查看>>
python 关于epoll的学习
查看>>
Python 内存管理
查看>>
Python 内嵌函数:它们有什么用处?
查看>>
Python 内置 sum 函数 vs. for 循环性能
查看>>
python 内置slice的用法
查看>>
Python 内置时间模块
查看>>
python 内部如何实现命名元组?
查看>>
Python 写Android App性能:入门到高级
查看>>
python 写入json数据到数据库
查看>>
Python 出现 TypeError: ‘encoding‘ is an invalid keyword argument for this function 解决方法
查看>>
python 出现 TypeError: ‘list‘ object is not callable 的解决方法
查看>>
python 函数1
查看>>
python 函数学习
查看>>
Python 函数随笔 map()函数,lambda自定义函数
查看>>
Python 分析天气,告诉你中秋应该去哪里
查看>>
python 列表中dict中key排序
查看>>
python 列表函数
查看>>
Python 列表删除相同的元素
查看>>
python 列表生成式
查看>>