#include<bits/stdc++.h>
#define l unsigned long long int
using namespace std;
l i, m, c = 1;
void happy(l n)
{
l r, d = 0;
if(n != 1)
c++;
while(n != 0)
{
r = n%10;
n = n/10;
d += (r*r);
}
n = d;
if(n<=9)
{
if(n == 1 || n == 7)
cout << i << " " << c << endl;
return;
}
happy(n);
}
int main()
{
int n, m, a = 0;
while(cin >> n >> m)
{
a++;
if(a > 1)
cout << endl;
for(i=n; i<=m; i++)
{
happy(i);
c = 1;
}
}
return 0;
}
#define l unsigned long long int
using namespace std;
l i, m, c = 1;
void happy(l n)
{
l r, d = 0;
if(n != 1)
c++;
while(n != 0)
{
r = n%10;
n = n/10;
d += (r*r);
}
n = d;
if(n<=9)
{
if(n == 1 || n == 7)
cout << i << " " << c << endl;
return;
}
happy(n);
}
int main()
{
int n, m, a = 0;
while(cin >> n >> m)
{
a++;
if(a > 1)
cout << endl;
for(i=n; i<=m; i++)
{
happy(i);
c = 1;
}
}
return 0;
}
Comments
Post a Comment