We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
in C++, I don't think there are a built in bigInteger like in Java or Python, so I made whatever I needed to make it work.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>#include<cmath>#include<string>#include<sstream>constexprsize_tmod=10000000000000000;// power of 10 relatively close to int64 max.voiddoubling(std::vector<size_t>&num){size_tret=0;for(inti=0;i<num.size();i++){size_tlocalNum=num[i];localNum=localNum*2+ret;ret=localNum/mod;num[i]=localNum%mod;}if(ret>0){num.push_back(ret);}}// for each test casevoidrun(intn){std::vector<size_t>num={1};for(inti=0;i<n;i++){doubling(num);}std::stringstreamnumStream;for(inti=num.size()-1;i>=0;i--){numStream<<num[i];}std::stringstrnum=numStream.str();size_tsum=0;for(charc:strnum){sum+=(static_cast<int>(c)-'0');}std::cout<<sum<<std::endl;}intmain(){intt;std::cin>>t;for(;t>0;t--){intn;std::cin>>n;run(n);}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #16: Power digit sum
You are viewing a single comment's thread. Return to all comments →
in C++, I don't think there are a built in bigInteger like in Java or Python, so I made whatever I needed to make it work.