結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー e869120e869120
提出日時 2017-03-08 20:40:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 800 ms
コード長 2,276 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 70,696 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 00:26:14
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,384 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 1 ms
4,384 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 1 ms
4,380 KB
testcase_64 AC 1 ms
4,380 KB
testcase_65 AC 1 ms
4,380 KB
testcase_66 AC 1 ms
4,380 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 2 ms
4,380 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 1 ms
4,380 KB
testcase_71 AC 1 ms
4,376 KB
testcase_72 AC 2 ms
4,376 KB
testcase_73 AC 1 ms
4,376 KB
testcase_74 AC 1 ms
4,376 KB
testcase_75 AC 2 ms
4,376 KB
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 2 ms
4,380 KB
testcase_78 AC 1 ms
4,376 KB
testcase_79 AC 1 ms
4,376 KB
testcase_80 AC 2 ms
4,380 KB
testcase_81 AC 2 ms
4,380 KB
testcase_82 AC 1 ms
4,376 KB
testcase_83 AC 1 ms
4,376 KB
testcase_84 AC 2 ms
4,376 KB
testcase_85 AC 2 ms
4,376 KB
testcase_86 AC 2 ms
4,376 KB
testcase_87 AC 2 ms
4,376 KB
testcase_88 AC 1 ms
4,380 KB
testcase_89 AC 2 ms
4,380 KB
testcase_90 AC 1 ms
4,376 KB
testcase_91 AC 1 ms
4,376 KB
testcase_92 AC 1 ms
4,380 KB
testcase_93 AC 1 ms
4,380 KB
testcase_94 AC 2 ms
4,376 KB
testcase_95 AC 1 ms
4,376 KB
testcase_96 AC 1 ms
4,380 KB
testcase_97 AC 1 ms
4,376 KB
testcase_98 AC 2 ms
4,376 KB
testcase_99 AC 2 ms
4,376 KB
testcase_100 AC 2 ms
4,376 KB
testcase_101 AC 1 ms
4,376 KB
testcase_102 AC 1 ms
4,376 KB
testcase_103 AC 2 ms
4,376 KB
testcase_104 AC 2 ms
4,380 KB
testcase_105 AC 1 ms
4,380 KB
testcase_106 AC 1 ms
4,380 KB
testcase_107 AC 1 ms
4,376 KB
testcase_108 AC 2 ms
4,380 KB
testcase_109 AC 2 ms
4,376 KB
testcase_110 AC 2 ms
4,376 KB
testcase_111 AC 1 ms
4,376 KB
testcase_112 AC 2 ms
4,376 KB
testcase_113 AC 2 ms
4,376 KB
testcase_114 AC 2 ms
4,376 KB
testcase_115 AC 2 ms
4,376 KB
testcase_116 AC 2 ms
4,376 KB
testcase_117 AC 1 ms
4,380 KB
testcase_118 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
long long K, L, R, U, V; string Y;
long long sums(long long P, long long Q) {
	if (P >= (1LL << Q))return (1LL << 62);
	if (P < 0)return -(1LL << 62);
	long long ret = 0, U = P;
	for (int i = 1; i <= Q; i++) {
		ret += ((U + 1) / 2) * to_string(i*i).size();
		U -= (U + 1) / 2;
	}
	return ret;
}
long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 63; i++) {
		if ((b / (1LL << i)) % 2 == 1)p *= q;
		q *= q;
		p %= m; q %= m;
	}
	return p;
}
void search() {
	//左の境界を探索
	long long L1 = -1, R1 = (1LL << K) + 1, M1;
	while (true) {
		M1 = (L1 + R1) / 2;
		long long Y1 = sums(M1 - 1, K), Y2 = sums(M1, K);
		if (Y1 < L && Y2 >= L) {
			U = M1; U++;
			if (Y2 - L >= 1) {
				long long I = M1, J = 1;
				while (I % 2 == 0) { I /= 2; J++; }
				Y += to_string(J*J).substr(to_string(J*J).size() - (Y2 - L), (Y2 - L));
			}
			break;
		}
		if (Y2 < L)L1 = M1;
		if (Y1 >= L)R1 = M1;
	}
	//右の境界を探索
	L1 = -1; R1 = (1LL << K) + 1;
	while (true) {
		M1 = (L1 + R1) / 2;
		long long Y1 = sums(M1, K), Y2 = sums(M1 + 1, K);
		if (Y1 <= R && Y2 > R) {
			V = M1;
			if (R - Y1 >= 1) {
				long long I = M1, J = 1; I++;
				while (I % 2 == 0) { I /= 2; J++; }
				Y += to_string(J*J).substr(0, (R - Y1));
			}
			break;
		}
		if (Y2 <= R)L1 = M1;
		if (Y1 > R)R1 = M1;
	}
}
int main() {
	cin >> K >> L >> R; L--; if (K >= 62)K = 62;
	if (R > sums((1LL << K) - 1, K)) { cout << "-1" << endl; return 0; }

	search();

	//端数部分の和と積を求める
	long long wa = 0, seki = 1;
	for (int i = 0; i < Y.size(); i++) {
		long long G = (Y[i] - '0'); if (G == 0)G = 10;
		wa += G; seki *= G;
	}
	//区間の部分の積と和を求める
	U--;
	for (int i = 1; i <= K; i++) {
		long long U1 = (U + 1) / 2;
		long long U2 = (V + 1) / 2;

		string T = to_string(i*i);
		long long w1 = 0, w2 = 1;
		for (int j = 0; j < T.size(); j++) {
			long long G = (T[j] - '0'); if (G == 0)G = 10;
			w1 += G; w2 *= G;
		}
		//cout << U2 - U1 << ' ' << U << ' ' << V << endl;
		wa += w1*(U2 - U1);
		seki *= modpow(w2, U2 - U1, 1000000007);
		seki %= 1000000007;
		U -= U1; V -= U2;
	}
	//出力
	cout << wa << ' ' << seki << endl;
	return 0;
}
0