56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
|
#include <bits/stdc++.h>
|
||
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
|
||
|
// 7.1, 7.2, 7.3 feladatok megoldasai
|
||
|
|
||
|
bool prim(int n) {
|
||
|
if (n == 1) return false;
|
||
|
if (n == 2) return false;
|
||
|
for (int i = 2; i < n; i++) {
|
||
|
if (n%i==0){
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
int convert(string a) {
|
||
|
int out = 0;
|
||
|
int counter = 1;
|
||
|
for (int i = a.size() - 1; i >= 0; i--) {
|
||
|
if (a[i] == '1') {
|
||
|
out += counter;
|
||
|
}
|
||
|
counter = counter *2;
|
||
|
}
|
||
|
return out;
|
||
|
|
||
|
}
|
||
|
|
||
|
int lnko(int n, int k) {
|
||
|
vector<int>osztok1;
|
||
|
vector<int>osztok2;
|
||
|
for (int i = 1; i <= n; i++) {
|
||
|
if (n%i==0) osztok1.push_back(i);
|
||
|
}
|
||
|
for (int i = 1; i <= k; i++) {
|
||
|
if (k%i==0) osztok2.push_back(i);
|
||
|
}
|
||
|
int out=1;
|
||
|
for (int i = 0; i < osztok1.size(); i++) {
|
||
|
for (int j = 0; j < osztok2.size(); j++) {
|
||
|
if ((osztok1[i] == osztok2[j]) && (osztok1[i] > out)) {
|
||
|
out = osztok1[i];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return out;
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
cout<<prim(13)<<' '<<prim(2)<<' '<<prim(6);
|
||
|
cout<<endl<<convert("0101101");
|
||
|
cout<<endl<<lnko(38, 14)<<' '<<lnko(16,12)<<' '<<lnko(432,527);
|
||
|
cout<<endl<<lnko(284,1283);
|
||
|
}
|