博客
关于我
将一个数开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 | Indico,一个超酷的 Python 库!
查看>>
python | isort,一个有趣的 自动整理导入语句 的Python 库!
查看>>
python | jinja,一个超酷的 Python 库!
查看>>
python | joblib,一个强大的 Python 库!
查看>>
python调用git bash_Python学习第70课-用Git Bash在命令行打开sublime
查看>>
python | jsonschema,一个实用的 验证 JSON 数据结构 Python 库!
查看>>
python课程的中期报告范文_课题研究中期总结报告范文
查看>>
python | lxml,一个超酷的 关于XML/HTML 文档 Python 库!
查看>>
python | mplfinance,一个有趣的金融数据可视化 Python 库!
查看>>
python | nipy,一个强大的关于 神经影像数据分析 的Python 库!
查看>>
python | NLTK,一个强大的 自然语言处理 Python 库!
查看>>
python | nupic,一个强大的 处理时间序列的Python 库!
查看>>
python | orange3,一个神奇的 Python 库!
查看>>
python | pdfminer,一个神奇的 关于PDF 文件的 Python 库!
查看>>
python | pendulum,一个有趣的 日期和时间 Python 库!
查看>>
python | pluginbase,一个神奇的 关于插件框架 的Python 库!
查看>>
python | ply,一个无敌的 词法和语法分析工具 的Python 库!
查看>>
python | py2exe,一个超酷的 Python 库!
查看>>
python | pyautogui,一个超酷的 Python 库!
查看>>
python | pybaobabdt,一个超强的 决策树可视化 Python 库!
查看>>