• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

練習用です。いろんなものがごちゃまぜです。


Commit MetaInfo

Revisionbbfaed61c9c636e5fd3ce6a6c6f10273074936ec (tree)
Time2017-03-13 12:56:48
Authorbellyoshi <tccwas@gmai...>
Commiterbellyoshi

Log Message

prime

Change Summary

Incremental Difference

--- /dev/null
+++ b/CPP/ALDS1_1/gcd.cpp
@@ -0,0 +1,23 @@
1+#include <iostream>
2+
3+using namespace std;
4+
5+int gcd(int a, int b){
6+ int mod = !0;
7+ while(mod != 0 ){
8+ mod = a % b;
9+ if (mod > b){
10+ a = mod;
11+ } else {
12+ a = b;
13+ b = mod;
14+ }
15+ }
16+ return a;
17+}
18+int main(int argc, char const *argv[]) {
19+ int x, y;
20+ cin >> x >> y;
21+ cout << gcd(x,y) << endl;
22+ return 0;
23+}
--- /dev/null
+++ b/CPP/ALDS1_1/prime.cpp
@@ -0,0 +1,36 @@
1+#include <iostream>
2+#include <cmath>
3+using namespace std;
4+
5+bool isprime(int number){
6+ if (number == 1){
7+ return false;
8+ }
9+
10+ if (number == 2){
11+ return true;
12+ }
13+ if (number % 2 == 0){
14+ return false;
15+ }
16+
17+ for(int i = 3; i < number; i+=2){
18+ if(number % i == 0)return false;
19+ }
20+ return true;
21+}
22+
23+int main(int argc, char const *argv[]) {
24+ int count;
25+ cin >> count;
26+ int prime_count = 0;
27+ for (int i = 0; i < count; i++) {
28+ int number;
29+ cin >> number;
30+ if (isprime(number)){
31+ prime_count++;
32+ }
33+ }
34+ cout << prime_count << endl;
35+ return 0;
36+}