Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <vector>
- void TwoPowerNoJutsu(std::vector<short> &source, short expo) {
- if (expo <= 3) {
- switch (expo) {
- case 0:
- source.emplace_back(1);
- return;
- case 1:
- source.emplace_back(2);
- return;
- case 2:
- source.emplace_back(4);
- return;
- case 3:
- source.emplace_back(8);
- return;
- }
- }
- short index = 0, remainder = 0, temp=0;
- source.emplace_back(6);
- source.emplace_back(1);
- while (expo > 4) {
- source[index] = source[index] * 2 + temp;
- temp = 0;
- if (source[index] >= 10) {
- remainder = source[index] / 10;
- if (index +1== source.size()) {
- source.emplace_back(remainder);
- source[index] = source[index] % 10;
- index=0;
- expo--;
- }
- else{
- source[index + 1] = source[index + 1] * 2 + remainder;
- if (source[index + 1] >= 10) {
- temp = source[index + 1] / 10;
- source[index + 1] = source[index + 1] % 10;
- }
- source[index] = source[index] % 10;
- index = index + 2;
- if (index >= source.size()) {
- source.emplace_back(temp);
- temp = 0;
- }
- }
- }
- else {
- index++;
- }
- if (index >= source.size()) {
- index = 0;
- expo--;
- }
- }
- if (source[source.size() - 1] == 0) {
- source.pop_back();
- }
- }
- void LogNoJutsu(std::vector<short> source, short expo) {
- std::cout << "2^" << expo << " = ";
- for (int i = source.size()-1; i >=0 ; i--) {
- std::cout << source[i];
- }
- std::cout<<"\n";
- }
- short main() {
- std::vector<short> a;
- short expo = 128;
- for (int i = 0; i <= expo; i++) {
- TwoPowerNoJutsu(a, i);
- LogNoJutsu(a, i);
- a.clear();
- a.empty();
- }
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement