Skip to content
100 changes: 99 additions & 1 deletion SuperPrime_HW.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,103 @@
#include <iostream>

#include<stdio.h>
int main() {
int p[1000] = {0};
int pp[1000] = {0};
int i = 2;
for(;i < 1000;i++){//筛数法
p[i] = i;
}

int j = 0;
i = 2;
for(; i < 1000;i++){//生成一个纯净的素数数组
if(p[i] == 0){
continue;
}
pp[j] = p[i];

//printf("A%d %d\n",pp[j],j);

j++;
int k = 2;
for(;(i * k) < 1000;k++){
p[i * k] = 0;
}
}
int ppn = j;

//printf("B%d\n",ppn);

//for(i = 0; i < j;i++){
// printf("C%d %d\n",pp[i],i);
//}


int sp;
int countsp = 0;
int sumsp = 0;
int max = 0;
int judge = 0;
int t;
for(t = 25; t < ppn;t++){

//printf("D%d\n",pp[t]);

sp = pp[t];
int g = sp % 10;
int s = (sp - g) % 100 / 10;
int b = (sp - 10 * s - g) / 100;
int sum = g + s + b;
int mul = g * s * b;
int mul2 = g * g + s * s + b * b;

//printf("E%d %d %d %d \n",sp,g,s,b);

judge = 0;
for(j = 0;j < ppn;j++){
if(pp[j] == sum){
judge++;

//printf("Q1\n");

break;
}
}

//printf("go\n");

for(j = 0;j < ppn;j++){
if(pp[j] == mul){
judge++;

//printf("Q2\n");

break;
}
}
;
for(j = 0;j < ppn;j++){
if(pp[j] == mul2){
judge++;

//printf("Q3\n");

break;
}
}

if(judge == 3){
countsp++;
sumsp += sp;
max = sp;

//printf("Q%d\n",sp);

}

}
printf("个数:%d 和:%d 最大:%d \n",countsp,sumsp,max);


return 0;
}
179 changes: 118 additions & 61 deletions SuperPrime_HW2.cpp
Original file line number Diff line number Diff line change
@@ -1,94 +1,151 @@
#include <iostream>
#include <vector>
#include<stdio.h>
class Nature {
private:
int num;
public:
Nature():num(0){
std::cout << "Default Create Nature as " << num << std::endl;
//std::cout << "Default Create Nature as " << num << std::endl;
}
Nature(int n):num(n) {
std::cout << "Create Nature as " << num << std::endl;
//std::cout << "Create Nature as " << num << std::endl;
}
Nature(const Nature &nat):num(nat.num){
std::cout << "Copy Create Nature as " << num << std::endl;
//std::cout << "Copy Create Nature as " << num << std::endl;
}
~Nature() {
std::cout << "Destroy Nature as " << num << std::endl;
//std::cout << "Destroy Nature as " << num << std::endl;
}
bool isPrime() {
if(num == 1 || num == 0)
return false;
for(int i = 2; i <= (int)sqrt(num); i++)
{
if(num % i == 0)
return false;
}
return true;
bool isSuperPrime(){
int p[1000] = {0};
int pp[1000] = {0};
int i = 2;
for(;i < 1000;i++){//筛数法
p[i] = i;
}

int j = 0;
i = 2;
for(; i < 1000;i++){//生成一个纯净的素数数组
if(p[i] == 0){
continue;
}
pp[j] = p[i];

//printf("A%d %d\n",pp[j],j);

j++;
int k = 2;
for(;(i * k) < 1000;k++){
p[i * k] = 0;
}
}

int ppn = j;
int countsp = 0;
int sumsp = 0;
int max = 0;
int judge = 0;
int t;
for(t = 25; t < ppn;t++){
num = pp[t];
int g = num % 10;
int s = (num - g) % 100 / 10;
int b = (num - 10 * s - g) / 100;
int sum = g + s + b;
int mul = g * s * b;
int mul2 = g * g + s * s + b * b;

//printf("E%d %d %d %d \n",sp,g,s,b);

judge = 0;
for(j = 0;j < ppn;j++){
if(pp[j] == sum){
judge++;

//printf("Q1\n");

break;
}
}

//printf("go\n");

for(j = 0;j < ppn;j++){
if(pp[j] == mul){
judge++;

//printf("Q2\n");

break;
}
}
;
for(j = 0;j < ppn;j++){
if(pp[j] == mul2){
judge++;

//printf("Q3\n");

break;
}
}

if(judge == 3){
return true;
}
return false;
}
int compare(const Nature &nat) {
if (num > nat.num)
return 1;
else if(num == nat.num)
return 0;

return -1;
}
bool compare(Nature a){
if(num < a.num){
return true;
}
return false;
}
private:
};
class SuperPrime : public Nature {
private:
int num;
public:
SuperPrime(int n):num(n) {
}
bool isPrime() {
Nature nat(num);
return nat.isPrime();
}
int compare(const SuperPrime &nat) {
if (num > nat.num)
return 1;
else if(num == nat.num)
return 0;

return -1;
int show(){
std::cout<< "max:"<< num <<std::endl;
}
};
class Container {
class SuperPrime {
private:
std::vector<SuperPrime> natures;
std::vector<Nature> natures;
public:
Container(int a, int b) {
std::cout << "Create SuperPrime from " << a << " to " << b << std::endl;
SuperPrime(int a, int b) {
//std::cout << "Create SuperPrime from " << a << " to " << b << std::endl;
for(int i = a; i < b; i++) {
SuperPrime nat(i);
std::cout << "HAHA" << std::endl;
if(nat.isSuperPrime())
natures.push_back(nat);
std::cout << "DDDDD" << std::endl;
Nature nat(i);
//std::cout << "HAHA" << std::endl;
natures.push_back(nat);
//std::cout << "DDDDD" << std::endl;
}
}
~Container() {
std::cout << "Destroy SuperPrime " << std::endl;
~SuperPrime() {
//std::cout << "Destroy SuperPrime " << std::endl;
}

SuperPrime max() {
std::vector<SuperPrime>::iterate it = natures.begin();
Nature max() {
std::vector<Nature>::iterator it = natures.begin();
Nature max(0);
for(; it != natures.end(); it ++) {
if (max.compare(*it)) {
for(; it != natures.end(); it++) {
if(it->isSuperPrime()) {

if (max.compare(*it)) {
max = *it;
}
}
}
}
return max;
}

};
int main() {
SuperPrime sp(10, 13);
int main(){
SuperPrime sp(100, 999);
Nature n = sp.max();
std::cout << "��󳬼�������" ;
n.show();

//std::cout << "max:"<< ;
//the three numbers,howmany are they,the max of them.
n.show();//the max of them

return 0;
}
}
Loading