```cpp
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
const int N = 1e5 + 5;
int l, r;
bool st[N];
int pfh(int k) {
int sum = 0;
while (k) {
sum += (k % 10) * (k % 10);
k /= 10;
}
return sum;
}
int isprime(int x) {
if (x == 1 || x == 2) return 0;
for (int i = 2; i <= x / i; i++)
if (x % i == 0)
return 1;
return 2;
}
int main() {
cin >> l >> r;
map<int, int> mp;
int flag = 0;
for (int i = l; i <= r; i++) {
int t = i, sum = i;
vector<int> ve;
while (t != -1) {
sum = pfh(sum);
t = sum;
if (find(ve.begin(), ve.end(), sum) != ve.end())
break;
ve.push_back(sum);
st[t] = true;
}
if (t == 1) mp[i] = ve.size();
}
for (auto& m : mp)
if (!st[m.first] && ++flag)
cout << m.first << ' ' << isprime(m.first) * m.second << endl;
if (!flag) puts("SAD");
return 0;
}