From c4bd1d1e571bc766877bca64daa76ead69962570 Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Sun, 28 Mar 2021 15:11:43 +0000 Subject: [PATCH 01/16] =?UTF-8?q?Create=20=E5=88=A4=E6=96=AD=E8=B6=85?= =?UTF-8?q?=E7=BA=A7=E7=B4=A0=E6=95=B0=20=E5=86=AF=E6=B0=B8=E9=94=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\260 \345\206\257\346\260\270\351\224\264" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" diff --git "a/\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" "b/\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" new file mode 100644 index 00000000..3a231e95 --- /dev/null +++ "b/\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" @@ -0,0 +1,41 @@ +#include +int prime[100]; +bool isprime(int n) ; + +int main() +{ + int n = 100 , cnt = 0 , sum = 0 ; + while ( n < 1000 ) + { + if ( isprime(n) ) + { + int a = 0 , b = 0 , c = 0 , m = n ; + c = m % 10 ; + b = ( m /= 10 ) % 10 ; + a = m / 10 ; //分割数字 + if ( isprime(a + b + c) && isprime(a * b * c) && isprime( a * a + b * b + c * c ) ) + { + prime[cnt ++] = n ; + sum += n ; + } + } + n ++ ; + } + std::cout << "超级素数的个数:" << cnt << std::endl ; + std::cout << "所有的超级素数之和:" << sum << std::endl ; + std::cout << "最大的超级素数:" << prime[cnt - 1] << std::endl ; + + return 0 ; +} + +bool isprime(int n) 、、判断素数 +{ + for ( int i = 2 ; i * i < n ; i ++ ) + { + if ( n % i == 0 ) + { + return false ; + } + } + return true ; +} From 5a1bb62cec8cb180e1fe378dcd899e74875324de Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Sun, 28 Mar 2021 16:18:35 -0800 Subject: [PATCH 02/16] =?UTF-8?q?Update=20=E5=88=A4=E6=96=AD=E8=B6=85?= =?UTF-8?q?=E7=BA=A7=E7=B4=A0=E6=95=B0=20=E5=86=AF=E6=B0=B8=E9=94=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\240\346\225\260 \345\206\257\346\260\270\351\224\264" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" "b/\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" index 3a231e95..5b58a591 100644 --- "a/\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" +++ "b/\345\210\244\346\226\255\350\266\205\347\272\247\347\264\240\346\225\260 \345\206\257\346\260\270\351\224\264" @@ -12,7 +12,7 @@ int main() int a = 0 , b = 0 , c = 0 , m = n ; c = m % 10 ; b = ( m /= 10 ) % 10 ; - a = m / 10 ; //分割数字 + a = m / 10 ; if ( isprime(a + b + c) && isprime(a * b * c) && isprime( a * a + b * b + c * c ) ) { prime[cnt ++] = n ; @@ -28,9 +28,9 @@ int main() return 0 ; } -bool isprime(int n) 、、判断素数 +bool isprime(int n) { - for ( int i = 2 ; i * i < n ; i ++ ) + for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { From 55b569013348e3d94b588697050956b492943466 Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Tue, 6 Apr 2021 05:30:17 -0800 Subject: [PATCH 03/16] Add files via upload --- ...4\345\257\271\350\261\241\357\274\211.cpp" | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 "\347\273\237\350\256\241\350\266\205\347\272\247\347\264\240\346\225\260\357\274\210\347\261\273\345\222\214\345\257\271\350\261\241\357\274\211.cpp" diff --git "a/\347\273\237\350\256\241\350\266\205\347\272\247\347\264\240\346\225\260\357\274\210\347\261\273\345\222\214\345\257\271\350\261\241\357\274\211.cpp" "b/\347\273\237\350\256\241\350\266\205\347\272\247\347\264\240\346\225\260\357\274\210\347\261\273\345\222\214\345\257\271\350\261\241\357\274\211.cpp" new file mode 100644 index 00000000..d76f5119 --- /dev/null +++ "b/\347\273\237\350\256\241\350\266\205\347\272\247\347\264\240\346\225\260\357\274\210\347\261\273\345\222\214\345\257\271\350\261\241\357\274\211.cpp" @@ -0,0 +1,111 @@ +#include +#include +class Nature +{ +private: + int num ; +public: + Nature(int n) + { + num = n ; + } + ~Nature(){} + + /*int add(Nature sp) + { + return num + sp.num ; + } + + bool compare(Nature sp) + { + if (num > sp.num) + return true ; + return false ; + }*/ + bool isPrime() + { + for ( int i = 2 ; i * i <= num ; i ++ ) + { + if ( num % i == 0 ) + return false ; + } + return true ; + } + bool isSuperPrime() + { + int xx = num , a , sum = 0 , mul = 1 , sqrsum = 0 ; + while ( xx != 0 ) + { + a = xx % 10 ; + sum += a ; + mul *= a ; + sqrsum += ( a * a ) ; + xx /= 10 ; + } + Nature mul1(mul) , sum1(sum) , sqrsum1(sqrsum) ; + if (mul == 0) + return false ; + else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) + return true ; + else + return false ; + } + int show() + { + return num ; + } +}; + +class SuperPrime +{ +private: + std::vector range ; +public: + SuperPrime(int a , int b) + { + for ( int i = a ; i < b ; i ++ ) + { + Nature nat(i) ; + if (nat.isSuperPrime()) + range.push_back(nat) ; + } + } + int max() + { + int Max = 0 ; + for (std::vector::iterator it = range.begin() ; it != range.end() ; it ++ ) + { + if ( it->show() > (it + 1)->show() ) + Max = it->show() ; + else + Max = (it + 1)->show() ; + } + return Max ; + } + + int sum() + { + int Sum = 0 ; + for (std::vector::iterator it = range.begin() ; it != range.end() ; it ++ ) + { + Sum += it->show() ; + } + return Sum ; + } + + int howmany() + { + return range.size(); + } +}; + +int main() +{ + SuperPrime sp(100 , 999) ; + std::cout << "ij" << sp.max() << std::endl ; + std::cout << "ĺͣ" << sp.sum() << std::endl ; + std::cout << "ĸ" << sp.howmany() << std::endl ; + return 0 ; +} + + From c988f9d6e680a34ab8312fbb1d45a082fc031c89 Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Tue, 13 Apr 2021 13:02:54 +0800 Subject: [PATCH 04/16] Update SuperPrime_HW.cpp --- SuperPrime_HW.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index 0e004b50..806e274c 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -1,5 +1,100 @@ #include +#include +class Nature +{ +private: + int num; -int main() { - return 0; +public: + Nature(int n) + { + num = n; + } + ~Nature() {} + + bool isPrime() + { + for (int i = 2; i * i <= num; i++) + { + if (num % i == 0) + return false; + } + return true; + } + bool isSuperPrime() + { + int xx = num, a, sum = 0, mul = 1, sqrsum = 0; + while (xx != 0) + { + a = xx % 10; + sum += a; + mul *= a; + sqrsum += (a * a); + xx /= 10; + } + Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); + if (mul == 0) + return false; + else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) + return true; + else + return false; + } + int show() + { + return num; + } +}; + +class SuperPrime +{ +private: + std::vector range; + +public: + SuperPrime(int a, int b) + { + for (int i = a; i < b; i++) + { + Nature nat(i); + if (nat.isSuperPrime()) + range.push_back(nat); + } + } + int max() + { + int Max = 0; + for (std::vector::iterator it = range.begin(); it != range.end(); it++) + { + if (it->show() > (it + 1)->show()) + Max = it->show(); + else + Max = (it + 1)->show(); + } + return Max; + } + + int sum() + { + int Sum = 0; + for (std::vector::iterator it = range.begin(); it != range.end(); it++) + { + Sum += it->show(); + } + return Sum; + } + + int howmany() + { + return range.size(); + } +}; + +int main() +{ + SuperPrime sp(100, 999); + std::cout << "超级素数的个数:" << sp.max() << std::endl; + std::cout << "所有的超级素数之和:" << sp.sum() << std::endl; + std::cout << "最大的超级素数:" << sp.howmany() << std::endl; + return 0; } From d2ccf5ff31e58708a3d65150e06c0d259d503ab4 Mon Sep 17 00:00:00 2001 From: fyk <2788745314@qq.com> Date: Sun, 25 Apr 2021 17:07:44 +0800 Subject: [PATCH 05/16] SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 150 +++++++++++++++++++++++++++++++-------------- 1 file changed, 104 insertions(+), 46 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 9f16866e..945cb04f 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -1,57 +1,115 @@ #include #include -class Nature { +class Nature +{ private: - int num; + 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; - } + /*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() + { + for (int i = 2; i * i <= num; i++) + { + if (num % i == 0) + return false; + } + return true; + } + bool isSuperPrime() + { + int xx = num, a, sum = 0, mul = 1, sqrsum = 0; + while (xx != 0) + { + a = xx % 10; + sum += a; + mul *= a; + sqrsum += (a * a); + xx /= 10; + } + Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); + if (mul == 0) + return false; + else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) + return true; + return false; + } + int show() + { + return num ; + } + int compare(const Nature &nat) + { + if (num > nat.num) + return 1 ; + else if (num == nat.num) + return 0 ; + return -1 ; + } + }; -class SuperPrime { +class SuperPrime +{ private: - std::vector natures; + std::vector natures; + int num_of_SP , sum_of_SP , maxn ; public: - SuperPrime(int a, int b) { - std::cout << "Create SuperPrime from " << a << " to " << b << std::endl; - for(int i = a; i < b; i++) { - Nature nat(i); - std::cout << "HAHA" << std::endl; - natures.push_back(nat); - std::cout << "DDDDD" << std::endl; - } - } - ~SuperPrime() { - std::cout << "Destroy SuperPrime " << std::endl; - } - - Nature max() { - std::vector::iterate it = natures.begin(); - Nature max(0); - for(; it != natures.end(); it ++) { - if(it->isSuperPrime()) { - if (max.compare(*it)) { - max = *it; + SuperPrime(int a, int b) + { + for(int i = a; i < b; i++) + { + Nature nat(i); + if (nat.isSuperPrime()) + { + natures.push_back(nat); + num_of_SP ++ ; + std::cout << "num_of_SP ++" << std::endl; + sum_of_SP += nat.show() ; + std::cout << "sum_of_SP =" << sum_of_SP << std::endl; + maxn = nat.show() ; + } + } - } + } + ~SuperPrime() + { + std::cout << "Destroy SuperPrime " << std::endl; + } + + int max() + { + return maxn ; + } + int number() + { + return num_of_SP ; + } + int sum() + { + return sum_of_SP ; } - return max; - } }; -int main() { - SuperPrime sp(10, 13); - Nature n = sp.max(); - std::cout << "��󳬼�������" ; - n.show(); - - return 0; +int main() +{ + SuperPrime sp(10, 14); + std::cout << "ij" << sp.max() << std::endl ; + std::cout << "ĸ" << sp.number() << std::endl ; + std::cout << "ĺͣ" << sp.sum()<< std::endl ; + + + return 0; } From 64d738ed776bef7213e4b6766e7ca6a65de8e03e Mon Sep 17 00:00:00 2001 From: fyk <2788745314@qq.com> Date: Sun, 25 Apr 2021 21:00:24 +0800 Subject: [PATCH 06/16] SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 7 ++-- SuperPrime_HW.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp index 945cb04f..88dc2854 100644 --- a/SuperPrime-HW2.cpp +++ b/SuperPrime-HW2.cpp @@ -70,7 +70,8 @@ class SuperPrime public: SuperPrime(int a, int b) { - for(int i = a; i < b; i++) + num_of_SP = 0 ; + for(int i = a; i < b; i++) { Nature nat(i); if (nat.isSuperPrime()) @@ -79,7 +80,7 @@ class SuperPrime num_of_SP ++ ; std::cout << "num_of_SP ++" << std::endl; sum_of_SP += nat.show() ; - std::cout << "sum_of_SP =" << sum_of_SP << std::endl; + std::cout << "sum_of_SP=" << sum_of_SP << std::endl; maxn = nat.show() ; } @@ -105,7 +106,7 @@ class SuperPrime }; int main() { - SuperPrime sp(10, 14); + SuperPrime sp(100, 999); std::cout << "ij" << sp.max() << std::endl ; std::cout << "ĸ" << sp.number() << std::endl ; std::cout << "ĺͣ" << sp.sum()<< std::endl ; diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index 0e004b50..00d60655 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -1,5 +1,100 @@ #include +#include +class Nature +{ +private: + int num; -int main() { - return 0; +public: + Nature(int n) + { + num = n; + } + ~Nature() {} + + bool isPrime() + { + for (int i = 2; i * i <= num; i++) + { + if (num % i == 0) + return false; + } + return true; + } + bool isSuperPrime() + { + int xx = num, a, sum = 0, mul = 1, sqrsum = 0; + while (xx != 0) + { + a = xx % 10; + sum += a; + mul *= a; + sqrsum += (a * a); + xx /= 10; + } + Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); + if (mul == 0) + return false; + else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) + return true; + else + return false; + } + int show() + { + return num ; + } +}; + +class SuperPrime +{ +private: + std::vector range; + +public: + SuperPrime(int a, int b) + { + for (int i = a; i < b; i++) + { + Nature nat(i); + if (nat.isSuperPrime()) + range.push_back(nat); + } + } + int max() + { + int Max = 0; + for (std::vector::iterator it = range.begin(); it != range.end(); it++) + { + if (it->show() > (it + 1)->show()) + Max = it->show(); + else + Max = (it + 1)->show(); + } + return Max; + } + + int sum() + { + int Sum = 0; + for (std::vector::iterator it = range.begin(); it != range.end(); it++) + { + Sum += it->show(); + } + return Sum; + } + + int howmany() + { + return range.size(); + } +}; + +int main() +{ + SuperPrime sp(100, 999); + std::cout << "ĸ" << sp.max() << std::endl; + std::cout << "еij֮ͣ" << sp.sum() << std::endl; + std::cout << "ij" << sp.howmany() << std::endl; + return 0; } From da70cf98bfca80f77809285f5183709f8e53861e Mon Sep 17 00:00:00 2001 From: fyk <2788745314@qq.com> Date: Sun, 25 Apr 2021 21:14:35 +0800 Subject: [PATCH 07/16] SuperPrimeHW2.cpp --- SuperPrimeHW2.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 SuperPrimeHW2.cpp diff --git a/SuperPrimeHW2.cpp b/SuperPrimeHW2.cpp new file mode 100644 index 00000000..88dc2854 --- /dev/null +++ b/SuperPrimeHW2.cpp @@ -0,0 +1,116 @@ +#include +#include +class Nature +{ +private: + 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() + { + for (int i = 2; i * i <= num; i++) + { + if (num % i == 0) + return false; + } + return true; + } + bool isSuperPrime() + { + int xx = num, a, sum = 0, mul = 1, sqrsum = 0; + while (xx != 0) + { + a = xx % 10; + sum += a; + mul *= a; + sqrsum += (a * a); + xx /= 10; + } + Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); + if (mul == 0) + return false; + else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) + return true; + return false; + } + int show() + { + return num ; + } + int compare(const Nature &nat) + { + if (num > nat.num) + return 1 ; + else if (num == nat.num) + return 0 ; + return -1 ; + } + +}; +class SuperPrime +{ +private: + std::vector natures; + int num_of_SP , sum_of_SP , maxn ; +public: + SuperPrime(int a, int b) + { + num_of_SP = 0 ; + for(int i = a; i < b; i++) + { + Nature nat(i); + if (nat.isSuperPrime()) + { + natures.push_back(nat); + num_of_SP ++ ; + std::cout << "num_of_SP ++" << std::endl; + sum_of_SP += nat.show() ; + std::cout << "sum_of_SP=" << sum_of_SP << std::endl; + maxn = nat.show() ; + } + + } + } + ~SuperPrime() + { + std::cout << "Destroy SuperPrime " << std::endl; + } + + int max() + { + return maxn ; + } + int number() + { + return num_of_SP ; + } + int sum() + { + return sum_of_SP ; + } +}; +int main() +{ + SuperPrime sp(100, 999); + std::cout << "ij" << sp.max() << std::endl ; + std::cout << "ĸ" << sp.number() << std::endl ; + std::cout << "ĺͣ" << sp.sum()<< std::endl ; + + + return 0; +} From bc658f8b8452f83c1cbc5357855cd0d20840d367 Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Sun, 25 Apr 2021 21:15:45 +0800 Subject: [PATCH 08/16] Delete SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 116 --------------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 SuperPrime-HW2.cpp diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp deleted file mode 100644 index 88dc2854..00000000 --- a/SuperPrime-HW2.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -class Nature -{ -private: - 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() - { - for (int i = 2; i * i <= num; i++) - { - if (num % i == 0) - return false; - } - return true; - } - bool isSuperPrime() - { - int xx = num, a, sum = 0, mul = 1, sqrsum = 0; - while (xx != 0) - { - a = xx % 10; - sum += a; - mul *= a; - sqrsum += (a * a); - xx /= 10; - } - Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); - if (mul == 0) - return false; - else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) - return true; - return false; - } - int show() - { - return num ; - } - int compare(const Nature &nat) - { - if (num > nat.num) - return 1 ; - else if (num == nat.num) - return 0 ; - return -1 ; - } - -}; -class SuperPrime -{ -private: - std::vector natures; - int num_of_SP , sum_of_SP , maxn ; -public: - SuperPrime(int a, int b) - { - num_of_SP = 0 ; - for(int i = a; i < b; i++) - { - Nature nat(i); - if (nat.isSuperPrime()) - { - natures.push_back(nat); - num_of_SP ++ ; - std::cout << "num_of_SP ++" << std::endl; - sum_of_SP += nat.show() ; - std::cout << "sum_of_SP=" << sum_of_SP << std::endl; - maxn = nat.show() ; - } - - } - } - ~SuperPrime() - { - std::cout << "Destroy SuperPrime " << std::endl; - } - - int max() - { - return maxn ; - } - int number() - { - return num_of_SP ; - } - int sum() - { - return sum_of_SP ; - } -}; -int main() -{ - SuperPrime sp(100, 999); - std::cout << "ij" << sp.max() << std::endl ; - std::cout << "ĸ" << sp.number() << std::endl ; - std::cout << "ĺͣ" << sp.sum()<< std::endl ; - - - return 0; -} From c49a373a1241046d40b5dcd0877851a724b362f3 Mon Sep 17 00:00:00 2001 From: fyk <2788745314@qq.com> Date: Sun, 25 Apr 2021 21:21:40 +0800 Subject: [PATCH 09/16] SuperPrime-HW2.cpp --- SuperPrime-HW2.cpp | 116 --------------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 SuperPrime-HW2.cpp diff --git a/SuperPrime-HW2.cpp b/SuperPrime-HW2.cpp deleted file mode 100644 index 88dc2854..00000000 --- a/SuperPrime-HW2.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -class Nature -{ -private: - 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() - { - for (int i = 2; i * i <= num; i++) - { - if (num % i == 0) - return false; - } - return true; - } - bool isSuperPrime() - { - int xx = num, a, sum = 0, mul = 1, sqrsum = 0; - while (xx != 0) - { - a = xx % 10; - sum += a; - mul *= a; - sqrsum += (a * a); - xx /= 10; - } - Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); - if (mul == 0) - return false; - else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) - return true; - return false; - } - int show() - { - return num ; - } - int compare(const Nature &nat) - { - if (num > nat.num) - return 1 ; - else if (num == nat.num) - return 0 ; - return -1 ; - } - -}; -class SuperPrime -{ -private: - std::vector natures; - int num_of_SP , sum_of_SP , maxn ; -public: - SuperPrime(int a, int b) - { - num_of_SP = 0 ; - for(int i = a; i < b; i++) - { - Nature nat(i); - if (nat.isSuperPrime()) - { - natures.push_back(nat); - num_of_SP ++ ; - std::cout << "num_of_SP ++" << std::endl; - sum_of_SP += nat.show() ; - std::cout << "sum_of_SP=" << sum_of_SP << std::endl; - maxn = nat.show() ; - } - - } - } - ~SuperPrime() - { - std::cout << "Destroy SuperPrime " << std::endl; - } - - int max() - { - return maxn ; - } - int number() - { - return num_of_SP ; - } - int sum() - { - return sum_of_SP ; - } -}; -int main() -{ - SuperPrime sp(100, 999); - std::cout << "ij" << sp.max() << std::endl ; - std::cout << "ĸ" << sp.number() << std::endl ; - std::cout << "ĺͣ" << sp.sum()<< std::endl ; - - - return 0; -} From 0ac85111b2efd5a0644c22332f2d2ebb6585612a Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Sun, 25 Apr 2021 21:27:04 +0800 Subject: [PATCH 10/16] Rename SuperPrimeHW2.cpp to SuperPrimeHW_2.cpp --- SuperPrimeHW2.cpp => SuperPrimeHW_2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename SuperPrimeHW2.cpp => SuperPrimeHW_2.cpp (90%) diff --git a/SuperPrimeHW2.cpp b/SuperPrimeHW_2.cpp similarity index 90% rename from SuperPrimeHW2.cpp rename to SuperPrimeHW_2.cpp index 88dc2854..2336d6a9 100644 --- a/SuperPrimeHW2.cpp +++ b/SuperPrimeHW_2.cpp @@ -107,9 +107,9 @@ class SuperPrime int main() { SuperPrime sp(100, 999); - std::cout << "ij" << sp.max() << std::endl ; - std::cout << "ĸ" << sp.number() << std::endl ; - std::cout << "ĺͣ" << sp.sum()<< std::endl ; + std::cout << "最大的超级素数:" << sp.max() << std::endl ; + std::cout << "超级素数的个数:" << sp.number() << std::endl ; + std::cout << "超级素数的和:" << sp.sum()<< std::endl ; return 0; From a4bb835fa3c3d18aba01162082cc1be822c7b46f Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Sun, 25 Apr 2021 21:34:40 +0800 Subject: [PATCH 11/16] Rename SuperPrimeHW_2.cpp to SuperPrime_HW2.cpp --- SuperPrimeHW_2.cpp => SuperPrime_HW2.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename SuperPrimeHW_2.cpp => SuperPrime_HW2.cpp (100%) diff --git a/SuperPrimeHW_2.cpp b/SuperPrime_HW2.cpp similarity index 100% rename from SuperPrimeHW_2.cpp rename to SuperPrime_HW2.cpp From d2062996a9aeb4aa58738d425f92646cb9620d22 Mon Sep 17 00:00:00 2001 From: fyk1239 <78726080+fyk1239@users.noreply.github.com> Date: Sun, 25 Apr 2021 21:48:23 +0800 Subject: [PATCH 12/16] Update SuperPrime_HW.cpp --- SuperPrime_HW.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp index 00d60655..806e274c 100644 --- a/SuperPrime_HW.cpp +++ b/SuperPrime_HW.cpp @@ -42,7 +42,7 @@ class Nature } int show() { - return num ; + return num; } }; @@ -93,8 +93,8 @@ class SuperPrime int main() { SuperPrime sp(100, 999); - std::cout << "ĸ" << sp.max() << std::endl; - std::cout << "еij֮ͣ" << sp.sum() << std::endl; - std::cout << "ij" << sp.howmany() << std::endl; + std::cout << "超级素数的个数:" << sp.max() << std::endl; + std::cout << "所有的超级素数之和:" << sp.sum() << std::endl; + std::cout << "最大的超级素数:" << sp.howmany() << std::endl; return 0; } From 81f21862100a6f9e6d6a5c76257a724c44ccad91 Mon Sep 17 00:00:00 2001 From: fyk1239 <2788745314@qq.com> Date: Sun, 25 Apr 2021 22:02:38 +0800 Subject: [PATCH 13/16] SuperPrime_HW.cpp --- SuperPrime_HW.cpp | 120 ---------------------------------------------- 1 file changed, 120 deletions(-) delete mode 100644 SuperPrime_HW.cpp diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp deleted file mode 100644 index 6c4a0e87..00000000 --- a/SuperPrime_HW.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -class Nature -{ -private: - int num; - -public: - Nature(int n) - { - num = n; - } - ~Nature() {} - - bool isPrime() - { - for (int i = 2; i * i <= num; i++) - { - if (num % i == 0) - return false; - } - return true; - } - bool isSuperPrime() - { - int xx = num, a, sum = 0, mul = 1, sqrsum = 0; - while (xx != 0) - { - a = xx % 10; - sum += a; - mul *= a; - sqrsum += (a * a); - xx /= 10; - } - Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); - if (mul == 0) - return false; - else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) - return true; - else - return false; - } - int show() - { -<<<<<<< HEAD -<<<<<<< HEAD - return num; -======= - return num ; ->>>>>>> a4bb835fa3c3d18aba01162082cc1be822c7b46f -======= - return num; ->>>>>>> d2062996a9aeb4aa58738d425f92646cb9620d22 - } -}; - -class SuperPrime -{ -private: - std::vector range; - -public: - SuperPrime(int a, int b) - { - for (int i = a; i < b; i++) - { - Nature nat(i); - if (nat.isSuperPrime()) - range.push_back(nat); - } - } - int max() - { - int Max = 0; - for (std::vector::iterator it = range.begin(); it != range.end(); it++) - { - if (it->show() > (it + 1)->show()) - Max = it->show(); - else - Max = (it + 1)->show(); - } - return Max; - } - - int sum() - { - int Sum = 0; - for (std::vector::iterator it = range.begin(); it != range.end(); it++) - { - Sum += it->show(); - } - return Sum; - } - - int howmany() - { - return range.size(); - } -}; - -int main() -{ - SuperPrime sp(100, 999); -<<<<<<< HEAD -<<<<<<< HEAD - std::cout << "超级素数的个数:" << sp.max() << std::endl; - std::cout << "所有的超级素数之和:" << sp.sum() << std::endl; - std::cout << "最大的超级素数:" << sp.howmany() << std::endl; -======= - std::cout << "ĸ" << sp.max() << std::endl; - std::cout << "еij֮ͣ" << sp.sum() << std::endl; - std::cout << "ij" << sp.howmany() << std::endl; ->>>>>>> a4bb835fa3c3d18aba01162082cc1be822c7b46f -======= - std::cout << "超级素数的个数:" << sp.max() << std::endl; - std::cout << "所有的超级素数之和:" << sp.sum() << std::endl; - std::cout << "最大的超级素数:" << sp.howmany() << std::endl; ->>>>>>> d2062996a9aeb4aa58738d425f92646cb9620d22 - return 0; -} From a31aa1b226dd645e35a046b46d38effd9bc05d25 Mon Sep 17 00:00:00 2001 From: fyk <2788745314@qq.com> Date: Sun, 25 Apr 2021 22:30:26 +0800 Subject: [PATCH 14/16] SuperPrime_HW.cpp --- SuperPrime_HW.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 SuperPrime_HW.cpp diff --git a/SuperPrime_HW.cpp b/SuperPrime_HW.cpp new file mode 100644 index 00000000..00d60655 --- /dev/null +++ b/SuperPrime_HW.cpp @@ -0,0 +1,100 @@ +#include +#include +class Nature +{ +private: + int num; + +public: + Nature(int n) + { + num = n; + } + ~Nature() {} + + bool isPrime() + { + for (int i = 2; i * i <= num; i++) + { + if (num % i == 0) + return false; + } + return true; + } + bool isSuperPrime() + { + int xx = num, a, sum = 0, mul = 1, sqrsum = 0; + while (xx != 0) + { + a = xx % 10; + sum += a; + mul *= a; + sqrsum += (a * a); + xx /= 10; + } + Nature mul1(mul), sum1(sum), sqrsum1(sqrsum); + if (mul == 0) + return false; + else if (this->isPrime() && mul1.isPrime() && sum1.isPrime() && sqrsum1.isPrime()) + return true; + else + return false; + } + int show() + { + return num ; + } +}; + +class SuperPrime +{ +private: + std::vector range; + +public: + SuperPrime(int a, int b) + { + for (int i = a; i < b; i++) + { + Nature nat(i); + if (nat.isSuperPrime()) + range.push_back(nat); + } + } + int max() + { + int Max = 0; + for (std::vector::iterator it = range.begin(); it != range.end(); it++) + { + if (it->show() > (it + 1)->show()) + Max = it->show(); + else + Max = (it + 1)->show(); + } + return Max; + } + + int sum() + { + int Sum = 0; + for (std::vector::iterator it = range.begin(); it != range.end(); it++) + { + Sum += it->show(); + } + return Sum; + } + + int howmany() + { + return range.size(); + } +}; + +int main() +{ + SuperPrime sp(100, 999); + std::cout << "ĸ" << sp.max() << std::endl; + std::cout << "еij֮ͣ" << sp.sum() << std::endl; + std::cout << "ij" << sp.howmany() << std::endl; + return 0; +} From b5efd1ac33e5436e4d99ac1a1602a6f801abfc24 Mon Sep 17 00:00:00 2001 From: Lake Hoo Date: Tue, 27 Apr 2021 18:29:05 +0800 Subject: [PATCH 15/16] Homework3 --- SuperPrime_HW3.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 SuperPrime_HW3.cpp diff --git a/SuperPrime_HW3.cpp b/SuperPrime_HW3.cpp new file mode 100644 index 00000000..9a9f3a2c --- /dev/null +++ b/SuperPrime_HW3.cpp @@ -0,0 +1,58 @@ +#include +#include +class Nature { +protected: + int num; +public: + Nature(int n) { + num = n; + } + virtual bool isPrime() { + for(int i = 2; i < num;i++) { + if(num % i == 0) + return false; + } + return true; + } + void show() { + std::cout << num << std::endl; + } +}; +class SuperPrime:public Nature { +private: +public: + SuperPrime(int n):Nature(n) { + } + bool isPrime() { + int tmp = num + 1; + int sum = 0, mul = 1, sqr = 0; + while(tmp != 0) { + tmp = tmp / 10; + int x = tmp % 10; + sum += x; + mul *= x; + sqr += x*x; + } + Nature nat(sum), nat1(mul), nat2(sqr); + return Nature::isPrime() && nat.isPrime() && nat1.isPrime()&& nat2.isPrime(); + } +}; +int main() { + //create some objects + std::vector sps; + for (int i = 100; i < 999; i++) { + Nature *nat = new SuperPrime(i); + if (nat->isPrime()) + sps.push_back(nat); + } + std::vector::iterator it; + for(it=sps.begin(); it!=sps.end();it++) { + (*it)->show(); + } + for(it=sps.begin(); it!=sps.end();it++) { + delete *it; + } + + //ij + return 0; +} From 3a657282d0477eaea12bf212f87aa062cfbd952e Mon Sep 17 00:00:00 2001 From: fyk <2788745314@qq.com> Date: Tue, 27 Apr 2021 20:52:34 +0800 Subject: [PATCH 16/16] SuperPrime_HW3.cpp --- SuperPrime_HW3.cpp | 113 +++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/SuperPrime_HW3.cpp b/SuperPrime_HW3.cpp index 9a9f3a2c..0b0f4e3d 100644 --- a/SuperPrime_HW3.cpp +++ b/SuperPrime_HW3.cpp @@ -1,58 +1,73 @@ #include #include -class Nature { +#include +class Nature +{ protected: - int num; + int num; public: - Nature(int n) { - num = n; - } - virtual bool isPrime() { - for(int i = 2; i < num;i++) { - if(num % i == 0) - return false; - } - return true; - } - void show() { - std::cout << num << std::endl; - } + Nature(int n) + { + num = n ; + } + virtual bool isPrime() + { + for(int i = 2; i <= sqrt(num) ; i ++ ) + { + if(num % i == 0) + return false ; + } + return true ; + } + void show() + { + std::cout << num << std::endl; + } }; -class SuperPrime:public Nature { +class SuperPrime:public Nature +{ private: public: - SuperPrime(int n):Nature(n) { - } - bool isPrime() { - int tmp = num + 1; - int sum = 0, mul = 1, sqr = 0; - while(tmp != 0) { - tmp = tmp / 10; - int x = tmp % 10; - sum += x; - mul *= x; - sqr += x*x; - } - Nature nat(sum), nat1(mul), nat2(sqr); - return Nature::isPrime() && nat.isPrime() && nat1.isPrime()&& nat2.isPrime(); - } + SuperPrime(int n):Nature(n) {} + bool isPrime() + { + int tmp = num ; + int sum = 0 , mul = 1 , sqr = 0; + while(tmp != 0) + { + int x = tmp % 10 ; + if ( !x ) + return false ; + tmp = tmp / 10 ; + sum += x ; + mul *= x ; + sqr += x * x ; + } + Nature nat(sum) , nat1(mul) , nat2(sqr) ; + return Nature::isPrime() && nat.isPrime() && nat1.isPrime()&& nat2.isPrime(); + } }; -int main() { - //create some objects - std::vector sps; - for (int i = 100; i < 999; i++) { - Nature *nat = new SuperPrime(i); - if (nat->isPrime()) - sps.push_back(nat); - } - std::vector::iterator it; - for(it=sps.begin(); it!=sps.end();it++) { - (*it)->show(); - } - for(it=sps.begin(); it!=sps.end();it++) { - delete *it; - } + +int main() +{ + //create some objects + std::vector sps ; + for (int i = 100 ; i < 999 ; i ++ ) + { + Nature *nat = new SuperPrime(i) ; + if (nat->isPrime()) + sps.push_back(nat) ; + } + std::vector::iterator it; + for(it = sps.begin(); it != sps.end() ; it ++) + { + (*it)->show() ; + } + for(it = sps.begin() ; it!=sps.end() ; it ++) + { + delete *it ; + } - //ij - return 0; -} + //ij + return 0 ; +}