#include<iostream>
#include<vector>
#include<unordered_map>
#include<map>
#include<cmath>
using namespace std;
unordered_map<int, int> xr;
int pm(int x){
if(x<2)
return 0;
else if(x==2)
return 1;
for (int p = ceil(sqrt(x)); p >= 2;--p)
if(x%p==0)
return 0;
return 1;
}
int rev(int x){
int ans = 0;
while(x>0){
ans += pow(x % 10,2);
x /= 10;
}
return ans;
}
int check(int xx){
unordered_map<int, int> mp;
int cnt = 0;
int x = xx;
while(x!=1){
mp[x] = 1;
x = rev(x);
xr[x] = 1;
if(mp.count(x))
return 0;
cnt++;
}
return cnt;
}
int main(){
int s, d;
cin >> s >> d;
map<int, int> ans;
for (int i = d; i >= s;--i){
int cnt = check(i);
if(cnt)
ans[i] = cnt;
}
for(auto&x:ans){
if(xr.count(x.first))
continue;
if(pm(x.first))
x.second *= 2;
cout << x.first << " " << x.second << "\n";
}
if(ans.size()==0)
cout << "SAD";
}
L2-029 特立独行的幸福 (25 分)
最新推荐文章于 2022-04-19 20:01:29 发布