Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW #144

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

NEW #144

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 69 additions & 76 deletions SuperPrime_HW2.cpp
Original file line number Diff line number Diff line change
@@ -1,94 +1,87 @@
#include <iostream>
#include <vector>
class Nature {
private:
int num;
private:
const int num; //数
public:
Nature():num(0){
std::cout << "Default Create Nature as " << num << std::endl;
}
Nature(int n):num(n) {
std::cout << "Create Nature as " << num << std::endl;
}
Nature(const Nature &nat):num(nat.num){
std::cout << "Copy Create Nature as " << num << std::endl;
}
~Nature() {
std::cout << "Destroy Nature as " << num << std::endl;
}
bool isPrime() {
if(num == 1 || num == 0)
~Nature();
Nature add(Nature sp); //求和
bool compare(Nature sp) { //比大小
if(num > sp.num)
return true;
return false;
for(int i = 2; i <= (int)sqrt(num); i++)
{
if(num % i == 0)
return false;
}
return true;
}
int compare(const Nature &nat) {
if (num > nat.num)
return 1;
else if(num == nat.num)
return 0;

return -1;
}
private:
bool isSuperPrime(int c)
{bool light=1;
int ge,shi,bai,he,ji,ping,a,b=0;
ge=c%10;shi=((c-ge)%100)/10;bai=(c-ge-shi*10)/100;
he=ge+shi+bai;ji=ge*shi*bai;ping=ge*ge+shi*shi+bai*bai;
if(ge!=0&&shi!=0&&bai!=0)
{for(int a=2;a<he;a++){if(he%a==0){b++;}}if(b!=0) {light=0;}
if(light==1){for(int a=2;a<ji;a++){if(ji%a==0){b++;}}
if(b!=0) {light=0;}}
if(light==1){for(int a=2;a<ping;a++){if(ping%a==0){b++;}}
if(b!=0) {light=0;}}}
else light=0;
return light;}
};
class SuperPrime : public Nature {

class SuperPrime {
private:
int num;
std::vector<Nature> range; //超级素数的容器
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;
SuperPrime(int a, int b) {
for(int i = a; i < b; i++) {
Nature nat(i);
if(nat.isSuperPrime(i)) //过滤器
range.push_back(nat);
}
}
};
class Container {
private:
std::vector<SuperPrime> natures;
public:
Container(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;
}
int max(int c) {
for(int n=100;n<=999;n++,c++) {
Nature nat(n);int max2;
if(nat.isSuperPrime(n))
c=n;
}
return c;
}

int howmany(int c) {
c=0;
for(int n=100;n<=999;n++,c++) {
Nature nat(n);int max2;
if(nat.isSuperPrime(n))
c++;
return c;
}
~Container() {
std::cout << "Destroy SuperPrime " << std::endl;
int sum(int c) {
c=0;
for(int n=100;n<=999;n++,c++) {
Nature nat(n);int max2;
if(nat.isSuperPrime(n))
c+=n;
return c;
}

SuperPrime max() {
std::vector<SuperPrime>::iterate it = natures.begin();
Nature max(0);
for(; it != natures.end(); it ++) {
if (max.compare(*it)) {
max = *it;
}
private:
void split(int x) {
int a, sum, mult, sqrsum;
while(x != 0) {
a = x % 10;
sum += a;
mult *= a;
sqrsum += a*a;
x = x / 10;
}
return max;
}
};
int main() {
SuperPrime sp(10, 13);
Nature n = sp.max();
std::cout << "��󳬼�������" ;
n.show();


int main()
{
SuperPrime sp(100, 999);
std::cout << "最大的超级素数:" << sp.max(100) << std::endl;
std::cout << "超级素数个数:" << sp.howmany(100) << std::endl;
std::cout << "超级素数的和:" << sp.sum(100) << std::endl;
return 0;
}
}
Empty file added test.txt
Empty file.
53 changes: 53 additions & 0 deletions 超级素数.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include<stdio.h>
#include<iostream>
#include<stdbool.h>
using namespace std;
class judge{
public:
bool sushu(int n,bool light)
{
light=0;
int b=0;
for(int a=2;a<n;a++)
{if(n%a==0){b++;}}
if(b==0){light=1;}
return light;
}
bool super(int c,bool light)
{
light=1;
int ge,shi,bai,he,ji,ping,a,b=0;
ge=c%10;shi=((c-ge)%100)/10;bai=(c-ge-shi*10)/100;
he=ge+shi+bai;ji=ge*shi*bai;ping=ge*ge+shi*shi+bai*bai;
if(ge!=0&&shi!=0&&bai!=0)
{for(int a=2;a<he;a++){if(he%a==0){b++;}}if(b!=0) {light=0;}
if(light==1){for(int a=2;a<ji;a++){if(ji%a==0){b++;}}
if(b!=0) {light=0;}}
if(light==1){for(int a=2;a<ping;a++){if(ping%a==0){b++;}}
if(b!=0) {light=0;}}}
else light=0;
return light;
}
};
int main()
{
int n,sushu[255]={},super[255]={},num=0,a2=0;
judge M;bool light;
for(n=100;n<=999;n++)
{light=M.sushu(n,light);
if(light==1){sushu[num]=n;num++;}
}
num=0;
for(n=100;n<=999;n++)
{light=M.super(n,light);
if(light==1){super[num]=n;printf("%d %d\n",super[num],num);num++;}
}
cout<<"����="<<num<<endl;
num--;
for(n=0;n<=num;n++)
{a2=a2+super[n];}
cout<<"��="<<a2<<endl;
cout<<"���="<<super[num]<<endl;
return 0;
}