forked from kalmar/DALGLI0
106 lines
2.8 KiB
C#
106 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WlasnosciPierscieni
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
int n;
|
|
if (args.Count() > 0)
|
|
{
|
|
if (!int.TryParse(args[0], out n))
|
|
{
|
|
Console.WriteLine("Invalid argument");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Podaj n");
|
|
if(!int.TryParse(Console.ReadLine(),out n))
|
|
{
|
|
Console.WriteLine("Invalid arguemnt");
|
|
return;
|
|
}
|
|
}
|
|
|
|
IEnumerable<int> pierscien = Enumerable.Range(0, n).ToList();
|
|
|
|
Console.WriteLine("\nElementy odwracalne:");
|
|
foreach (int i in pierscien)
|
|
{
|
|
foreach (int j in pierscien)
|
|
{
|
|
if ((i * j) % n == 1)
|
|
{
|
|
Console.Write(i + " ");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("\nDzielniki zera:");
|
|
foreach (int i in pierscien)
|
|
{
|
|
foreach (int j in pierscien)
|
|
{
|
|
if (j == 0)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
Console.Write("0 ");
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if ((i * j) % n == 0)
|
|
{
|
|
Console.Write(i + " ");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("\nElementy nilpotentne:");
|
|
List<int> dzielniki = new List<int>();
|
|
int current, pow;
|
|
foreach (int i in pierscien)
|
|
{
|
|
current = i;
|
|
pow = 2;
|
|
dzielniki.Clear();
|
|
while (!dzielniki.Contains(current))
|
|
{
|
|
dzielniki.Add(current);
|
|
current = (int)(Math.Pow(i,pow)) % n;
|
|
if (current == 0)
|
|
{
|
|
Console.Write(i + " ");
|
|
break;
|
|
}
|
|
pow++;
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("\nElementy idempotentne:");
|
|
foreach (int i in pierscien)
|
|
{
|
|
if ((i * i) % n == i)
|
|
{
|
|
Console.Write(i + " ");
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("\nEnd");
|
|
Console.ReadKey();
|
|
|
|
|
|
}
|
|
}
|
|
}
|