Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #define _CRT_SECURE_NO_WARNINGS
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- #include <iomanip>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define mh() make_heap()
- #define poph() pop_heap()
- #define pushh() push_heap()
- #define sor(n) n.begin(), n.end()
- #define rsor(n) n.rbegin(), n.rend()
- #define mp make_pair
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define p(T) pair<T,T>
- #define toch(x) cout.precision(x), cout.setf(ios::fixed)
- #define znac(l) abs(l)/l
- #define IOS ios::sync_with_stdio(false)
- #define IOSB cin.tie(0), cout.tie(0);
- const ll ok = ll(1e9 + 7);
- char arr[8110][910];
- char arr1[8110][910];
- int main()
- {
- IOSB;
- IOS;
- #ifdef TheCompiler
- files;
- #endif
- arr[1][1] = '1';
- arr[4][2] = '2';
- arr[9][3] = '3';
- arr[16][4] = '4';
- arr[25][5] = '5';
- arr[36][6] = '6';
- arr[49][7] = '7';
- arr[64][8] = '8';
- arr[81][9] = '9';
- arr1[1][1] = 1;
- arr1[4][2] = 1;
- arr1[9][3] = 1;
- arr1[16][4] = 1;
- arr1[25][5] = 1;
- arr1[36][6] = 1;
- arr1[49][7] = 1;
- arr1[64][8] = 1;
- arr1[81][9] = 1;
- for(int i=1;i<=8100;i++)
- for (int j = 1; j <= 900; j++)
- {
- for (int k = 1; k <= 9; k++)
- {
- if (arr[i][j] != '\0'&&i + k*k<=8100&&j+k<=900&&arr1[i][j]<100)
- {
- if (arr[i + k*k][j + k] != '\0')
- {
- if (arr1[i][j] + 1 <= arr1[i + k*k][j + k])
- {
- arr[i + k*k][j + k] = k + '0';
- arr1[i + k*k][j + k]= arr1[i][j] + 1;
- }
- }
- else
- {
- arr[i + k*k][j + k] = k + '0';
- arr1[i + k*k][j + k]= arr1[i][j] + 1;
- }
- }
- }
- }
- ll n;
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- ll a, b;
- cin >> a >> b;
- if (a == 0 && b == 0)
- {
- cout << 0 << endl;
- }
- else
- if (b <= 8100 && a <= 900) {
- if (arr[b][a] != '\0')
- {
- if (arr1[b][a] > 100)
- cout << "No solution" << endl;
- else
- {
- string s = "";
- while (b != 0 && a != 0)
- {
- ll p = arr[b][a] - '0';
- b -= p*p;
- a -= p;
- s += p + '0';
- }
- sort(sor(s));
- cout << s << endl;
- }
- }
- else
- cout << "No solution" << endl;
- }
- else
- cout << "No solution" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement