97 lines
1.6 KiB
C++
97 lines
1.6 KiB
C++
#include <iostream>
|
|
#include <conio.h>
|
|
|
|
|
|
using namespace std;
|
|
|
|
int NWD(int x, int y)
|
|
{
|
|
if(y!=0)
|
|
return NWD(y,x%y);
|
|
return x;
|
|
}
|
|
|
|
int poteguj(int pod, int wyk)
|
|
{
|
|
int w = 1;
|
|
for (int i = 0; i<wyk; i++)
|
|
w=pod*w;
|
|
return w;
|
|
}
|
|
|
|
int Elementy_odwracalne(int a){
|
|
for(int i=0;i<a;i++){
|
|
if(NWD(a,i)==1){
|
|
cout<< i << " ";
|
|
}
|
|
}
|
|
}
|
|
|
|
int Dzielniki_zera(int b){
|
|
for(int i=0;i<b;i++){
|
|
for(int j=1;j<b;j++){
|
|
int k = i*j;
|
|
if(k%b==0){
|
|
cout << i << " ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int Elementy_nilpotentne(int c){
|
|
for(int i=0;i<c;i++){
|
|
for(int j=2;j<c;j++){
|
|
int m = poteguj(i,j);
|
|
if(m%c==0){
|
|
cout << i << " ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int Elementy_idempotentne(int d){
|
|
for(int i=0;i<d;i++){
|
|
int w = i*i;
|
|
if(w%d==i){
|
|
cout << i << " ";
|
|
}
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
do {
|
|
cout << "Podaj n:";
|
|
int pierscien;
|
|
cin >> pierscien ;
|
|
|
|
cout << "Elementy odwracalne: ";
|
|
cout<<"( ";
|
|
Elementy_odwracalne(pierscien);
|
|
cout << ")" << endl;
|
|
|
|
cout << "Dzielniki zera: ";
|
|
cout<<"( ";
|
|
Dzielniki_zera(pierscien);
|
|
cout << ")" << endl;
|
|
|
|
cout << "Elementy nilpotentne: ";
|
|
cout<<"( ";
|
|
Elementy_nilpotentne(pierscien);
|
|
cout << ")" << endl;
|
|
|
|
cout << "Elementy idempotentne: ";
|
|
cout<<"( ";
|
|
Elementy_idempotentne(pierscien);
|
|
cout << ")" << endl <<endl;
|
|
|
|
cout << "Aby zakonczyc wcisnij ESC" << endl;
|
|
cout << "Aby policzyc ponownie wybierz dowolny inny klawisz" << endl << endl;
|
|
}
|
|
|
|
while (getch() != 27);
|
|
|
|
return 0;
|
|
|
|
}
|