Created
September 22, 2014 13:35
-
-
Save katsuobushiFPGA/f2fc8879c8c42210d06c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<boost/multiprecision/cpp_int.hpp> | |
//名前空間定義 | |
namespace mp = boost::multiprecision; | |
mp::cpp_int multiply(mp::cpp_int& x,int y){ | |
mp::cpp_int tmp = 1; | |
for (int i = 0; i < y; i++){ | |
tmp *= x; | |
} | |
return tmp; | |
}; | |
mp::cpp_int kaijo(int x){ | |
mp::cpp_int tmp = 1; | |
for (int i = 1; i < x+1; i++){ | |
tmp *= i; | |
} | |
return tmp; | |
}; | |
int main(){ | |
mp::cpp_int ans = 1; | |
mp::cpp_int ans_tmp = 1;//途中計算の答え | |
mp::cpp_int temp_kaijo = 1;//階乗保存配列 | |
mp::cpp_int e_val = 1;//eの階乗 | |
for (unsigned int i = 1; i < 10; i++){ | |
if (i == 1){ | |
ans += 1; | |
} | |
else if (i == 2){ | |
ans += e_val; | |
} | |
else{ | |
ans += multiply(e_val, i - 1) / kaijo(i - 1); | |
} | |
} | |
//e^x = 1 + x + x^2/2 + x^3/3! ... | |
std::cout << ans << std::endl; | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment