Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace prac_5_ex_2
- {
- class Program
- {
- static int SumOfDividers(int a)
- {
- int s = 0;
- for (int i = 1; i <= Math.Sqrt(a); ++i)
- if (a % i == 0)
- {
- if (a / i != i) s += i + a / i;
- else s += i;
- }
- return s;
- }
- static bool IsPrime(int a)
- {
- int cnt = 0;
- for (int i = 1; i <= Math.Sqrt(a); ++i)
- {
- if (a % i == 0) cnt++;
- }
- if (cnt == 1) return true;
- else return false;
- }
- static void Main(string[] args)
- {
- //example
- /* Console.Write("Введите n: ");
- int n = int.Parse(Console.ReadLine());*/
- //a)
- /*Console.Write("a)\n\ta = ");
- int aa = int.Parse(Console.ReadLine());
- Console.Write("\tb = ");
- int ba = int.Parse(Console.ReadLine());
- for (int i = aa; i <= ba; i++)
- Console.WriteLine("\t{0} — {1}", i, SumOfDividers(i));*/
- //b)
- /*Console.Write("a)\n\ta = ");
- int ab = int.Parse(Console.ReadLine());
- Console.Write("\tb = ");
- int bb = int.Parse(Console.ReadLine());
- Console.Write("\tn = ");
- int n = int.Parse(Console.ReadLine());
- for (int i = ab; i <= bb; i++)
- if (SumOfDividers(i) == n) Console.WriteLine("\t{0}", i);*/
- //c)
- Console.Write("a)\n\ta = ");
- int ac = int.Parse(Console.ReadLine());
- Console.Write("\tb = ");
- int bc = int.Parse(Console.ReadLine());
- int max = 0;
- for (int i = bc; i > ac; i--)
- if (!IsPrime(bc)) max = SumOfDividers(ac);
- for (int i = ac+1; i <= bc; i++)
- if (SumOfDividers(i) == max) Console.WriteLine("\t{0}", i);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement