Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 2000 + 100;
- struct BigInteger {
- int length;
- int num[maxn];
- void clear() {
- length = 0;
- memset(num, 0, sizeof(num));
- }
- BigInteger() {
- clear();
- length = 1;
- }
- BigInteger(int x) {
- clear();
- if (x == 0) {
- length = 1;
- return ;
- }
- while (x != 0) {
- num[length++] = x % 10;
- x /= 10;
- }
- }
- BigInteger(const string &str) {
- clear();
- for (int i = str.length() - 1; i >= 0; --i) {
- if (str[i] == '.') {
- continue;
- }
- num[length++] = str[i] - '0';
- }
- fixLength();
- }
- void fixLength() {
- for (int i = maxn - 1; i >= 0; --i) {
- if (num[i] != 0) {
- length = i + 1;
- return ;
- }
- }
- length = 1;
- }
- void fix() {
- int s = 0;
- for (int i = 0; i < maxn; ++i) {
- num[i] += s;
- s = num[i] / 10;
- num[i] %= 10;
- }
- fixLength();
- }
- };
- BigInteger operator+(const BigInteger &a, const BigInteger &b) {
- BigInteger c;
- int len = max(a.length, b.length);
- for (int i = 0; i < len; ++i) {
- c.num[i] = a.num[i] + b.num[i];
- }
- c.fix();
- return c;
- }
- BigInteger operator*(const BigInteger &a, const BigInteger &b) {
- BigInteger c;
- for (int i = 0; i < a.length; ++i) {
- for (int j = 0; j < b.length; ++j) {
- c.num[i + j] += a.num[i] * b.num[j];
- }
- }
- c.fix();
- return c;
- }
- ostream& operator<<(ostream &out, const BigInteger &x) {
- for (int i = x.length - 1; i >= 0; --i) {
- out << x.num[i];
- }
- return out;
- }
- BigInteger fastPow(BigInteger res, int n) {
- BigInteger ans;
- for (ans = 1; n != 0; n >>= 1) {
- if ((n & 1) == 1) {
- ans = ans * res;
- }
- res = res * res;
- }
- return ans;
- }
- int n, dig;
- string d;
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif
- ios::sync_with_stdio(false);
- cin >> n >> d;
- for (int i = d.length() - 1; i >= 0; --i) {
- if (d[i] == '.') {
- dig = d.length() - i - 1;
- break;
- }
- }
- BigInteger ans = fastPow(2, n) * BigInteger(d);
- if (ans.num[dig - 1] >= 5) {
- ans = ans + fastPow(10, dig);
- }
- for (int i = ans.length - 1; i >= dig; --i) {
- cout << ans.num[i];
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement