-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsuperprime.cpp
More file actions
59 lines (57 loc) · 1.05 KB
/
Copy pathsuperprime.cpp
File metadata and controls
59 lines (57 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
using namespace std;
class Number {
public:
Number(int x):n(x) {}
Number(const Number&x):n(x.n) {}
~Number(){}
bool isPrime()
{
if (n==1) return false;
for(int i=2;i*i<=n;i++) if(n%i==0) return false;
return true;
}
private:
int n;
};
class SuperPrime : public Number
{
public:
SuperPrime(int x):Number(x),nn(x){}
~SuperPrime(){}
Number getsum()
{
int tot=0,t=nn;
while(t) tot+=t%10,t/=10;
return Number(tot);
}
Number getmult()
{
int tot=1,t=nn;
while(t) tot*=t%10,t/=10;
return Number(tot);
}
Number getsquare()
{
int tot=0,t=nn;
while(t) tot+=(t%10)*(t%10),t/=10;
return Number(tot);
}
private:
int nn;
};
int main() {
SuperPrime sp(113);
if(sp.isPrime()) {
printf("sp is a prime\n");
}
if(sp.getsum().isPrime()) {
printf("sp'sumbit is a prime\n");
}
if(sp.getmult().isPrime()) {
printf("sp'multibit is a prime\n");
}
if(sp.getsquare().isPrime()) {
printf("sp'squareSumBit is a prime\n");
}
}