File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ // https://www.codewars.com/kata/5539fecef69c483c5a000015
2
+ #include < cmath>
3
+ #include < bits/stdc++.h>
4
+ #include < string>
5
+ class BackWardsPrime
6
+ {
7
+ public:
8
+ static std::string backwardsPrime (long long start, long long end){
9
+ std::string res;
10
+ bool prime, backwardsPrime, notSame;
11
+ const auto sep = " " ;
12
+ for (auto i = start;i<=end;i++){
13
+ auto reversed_item = reverse_item (i);
14
+ prime = isPrime (i);
15
+ backwardsPrime = isPrime (reversed_item);
16
+ notSame = i != reversed_item;
17
+ if (prime&¬Same&&backwardsPrime){
18
+ res += std::to_string (i) + sep;
19
+ }
20
+ }
21
+ return res.substr (0 ,res.length ()-1 );
22
+ };
23
+ static long long reverse_item (long long item){
24
+ std::string s_item = std::to_string (item);
25
+ std::reverse (s_item.begin (),s_item.end ());
26
+ return std::stoll (s_item);
27
+ }
28
+ static bool isPrime (long long item){
29
+ auto sq_root = std::sqrt (item);
30
+ for (auto i = 2 ; i <= sq_root; i++){
31
+ if (item % i == 0 ) {
32
+ return false ;
33
+ }
34
+ }
35
+ return true ;
36
+ };
37
+ };
You can’t perform that action at this time.
0 commit comments