#include #include #include using namespace std; int main(void){ int k, n; cin >> k >> n; vector exi(10, false); int nn=n; vector yakusu(nn+1, -1), prime; for(int i=2; i<=nn; i++){ if(yakusu[i]!=-1) continue; int copy=i; prime.push_back(i); while(copy<=nn){ if(yakusu[copy]==-1) yakusu[copy]=i; copy+=i; } } auto f=[&](auto f, int now){ int copy=now, ans=0; while(copy){ ans+=copy%10; copy/=10; } if(ans<10) return ans; else return f(f, ans); }; int left=lower_bound(prime.begin(), prime.end(), k)-prime.begin(); int maxi=-1, right=left, m=prime.size(), ansleft; vector hash; for(auto p:prime) hash.push_back(f(f, p)); while(leftright) right=left; while(right=m) break; exi[hash[left]]=false; left++; } cout << ansleft << endl; return 0; }