結果

問題 No.219 巨大数の概算
ユーザー Kmcode1Kmcode1
提出日時 2015-05-29 23:40:01
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,308 bytes
コンパイル時間 2,539 ms
コンパイル使用メモリ 106,780 KB
実行使用メモリ 15,120 KB
最終ジャッジ日時 2023-09-20 17:12:08
合計ジャッジ時間 8,700 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;

string pluss(string a, string b, bool flag = false){
	if (!flag){
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
	}
	if (a.size() > b.size()){
		swap(a, b);
	}
	string ans;
	ans.clear();
	long long int want = 0;
	for (int i = 0; i < a.size(); i++){
		long long int val = a[i] - '0';
		val += b[i] - '0';
		val += want;
		want = val / 10LL;
		val %= 10LL;
		ans.push_back(val + '0');
	}
	for (int j = a.size(); j < b.size(); j++){
		long long int val = 0;
		val += b[j] - '0';
		val += want;
		want = val / 10LL;
		val %= 10LL;
		ans.push_back(val + '0');
	}
	while (want){
		ans.push_back(want % 10 + '0');
		want /= 10;
	}
	if (!flag){
		reverse(ans.begin(), ans.end());
	}
	return ans;
}
string mult(string a, string b, bool flag = false){
	if (!flag){
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
	}
	string ans = "0";
	string pas;
	string kari;
	pas.clear();
	for (int i = 0; i < b.size(); i++){
		long long int bb = b[i] - '0';
		long long int tmp = 0;
		kari = pas;
		for (int j = 0; j < a.size(); j++){
			long long int val = (long long int)(a[j] - '0')*bb;
			val += tmp;
			tmp = val / 10LL;
			val %= 10LL;
			kari.push_back(val + '0');
		}
		while (tmp){
			kari.push_back((tmp % 10LL) + '0');
			tmp /= 10LL;
		}
		ans = pluss(ans, kari, true);
		//end
		pas.push_back('0');
	}
	if (!flag){
		reverse(ans.begin(), ans.end());
	}
	return ans;
}
string ppow(string a, long long int b){
	string res = "1";
	while (b){
		if ((b & 1LL)){
			res = mult(res,a);
		}
		a = mult(a, a);
		b >>= 1LL;
	}
	return res;
}
char buf[20];
int main(){
	int n;
	scanf("%d", &n);
	while (n--){
		string a;
		long long int b;
		scanf("%s", buf);
		scanf("%lld", &b);
		a = buf;
		a = ppow(a, b);
		printf("%d %d %d\n", a[0]-'0', a[1]-'0', a.size()-1);
	}
	return 0;
}
0