一个算法问题,有兴趣的进来看看 怎样把一个数除以3的运算用移位和加法来表达,要求效率高。准确到个位即可。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是一个级数问题!|x|<11+x^2+x^3+x^4+...+x^n=1/(1-x)1/3=1/4+1/8(1-1/2+1/4-1/8...)是一个无穷递缩等比数列 公比q=-1/2你需要根据数据的位数编写代码!假设是32位的数据那你的数列的最后一位为-1/(2^32)(舍掉)程序写起来有点麻烦如:#include "stdafx.h"#include "iostream.h"int main(int argc, char* argv[]){ int x; cout<<"Please input the number:"; cin>>x; int nResult=0; int index; nResult+=(x>>2); for(index=3;index<32;index+=2) nResult+=(x>>index); for(index=4;index<32;index+=2) nResult-=(x>>index); cout<<"The result is: "<<nResult<<endl; return 0;}----------------------PS.程序对一些临界值得测试结果不对!你自己调试以下。我想我的思路还是正确的!解决了后告诉我![email protected] 这是一个级数问题!|x|<11+x^2+x^3+x^4+...+x^n=1/(1-x)1/3=1/4+1/8(1-1/2+1/4-1/8...)是一个无穷递缩等比数列 公比q=-1/2你需要根据数据的位数编写代码!假设是32位的数据那你的数列的最后一位为-1/(2^32)(舍掉)程序写起来有点麻烦如:#include "stdafx.h"#include "iostream.h"int main(int argc, char* argv[]){ int x; cout<<"Please input the number:"; cin>>x; int nResult=0; int index; nResult+=(x>>2); for(index=3;index<32;index+=2) nResult+=(x>>index); for(index=4;index<32;index+=2) nResult-=(x>>index); cout<<"The result is: "<<nResult<<endl; return 0;}----------------------PS.程序对一些临界值得测试结果不对!你自己调试以下。我想我的思路还是正确的!解决了后告诉我![email protected] CxImage使用的奇怪编译问题 EndDialog(0)?? 如何用odbc方式在List里显示数据库表记录内容 清问文本编辑框的快捷键怎么设置 本人在校研究生,暑假欲兼职!!! 【新手】MS VC6 编辑文本文件时,find 的 Mark all 标记如何清除掉? 为何我的程序一调用另一个函数就出错? 子线程不进循环并且自动结束 GG:如何通过网络播放和接收DVD (MPEG-2格式的)视频流 有未处理的异常,读取位置发生访问冲突求大佬帮忙 编译出错,请帮忙 这个程序为什么不能编辑通过
|x|<1
1+x^2+x^3+x^4+...+x^n=1/(1-x)
1/3=1/4+1/8(1-1/2+1/4-1/8...)
是一个无穷递缩等比数列 公比q=-1/2
你需要根据数据的位数编写代码!
假设是32位的数据那你的数列的最后一位为-1/(2^32)(舍掉)
程序写起来有点麻烦如:
#include "stdafx.h"
#include "iostream.h"
int main(int argc, char* argv[])
{
int x;
cout<<"Please input the number:";
cin>>x; int nResult=0;
int index; nResult+=(x>>2);
for(index=3;index<32;index+=2)
nResult+=(x>>index);
for(index=4;index<32;index+=2)
nResult-=(x>>index); cout<<"The result is: "<<nResult<<endl; return 0;
}----------------------
PS.程序对一些临界值得测试结果不对!你自己调试以下。
我想我的思路还是正确的!
解决了后告诉我!
[email protected]
|x|<1
1+x^2+x^3+x^4+...+x^n=1/(1-x)
1/3=1/4+1/8(1-1/2+1/4-1/8...)
是一个无穷递缩等比数列 公比q=-1/2
你需要根据数据的位数编写代码!
假设是32位的数据那你的数列的最后一位为-1/(2^32)(舍掉)
程序写起来有点麻烦如:
#include "stdafx.h"
#include "iostream.h"
int main(int argc, char* argv[])
{
int x;
cout<<"Please input the number:";
cin>>x; int nResult=0;
int index; nResult+=(x>>2);
for(index=3;index<32;index+=2)
nResult+=(x>>index);
for(index=4;index<32;index+=2)
nResult-=(x>>index); cout<<"The result is: "<<nResult<<endl; return 0;
}----------------------
PS.程序对一些临界值得测试结果不对!你自己调试以下。
我想我的思路还是正确的!
解决了后告诉我!
[email protected]