Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SumAndProduct
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- bool isFound = false;
- for (int i = 1; i < 9; i++)
- {
- for (int j = 9; j > i; j--)
- {
- for (int k = 0; k < 9; k++)
- {
- for (int l = 9; l > k; l--)
- {
- if ((i + j + k + l) == i * j * k * l && num % 10 == 5)
- {
- Console.WriteLine($"{i}{j}{k}{l}");
- isFound = true;
- }
- if (i * j * k * l / (i + j + k + l) == 3 && num % 3 == 0)
- {
- Console.WriteLine($"{l}{k}{j}{i}");
- isFound = true;
- }
- if (isFound)
- {
- break;
- }
- }
- if (isFound)
- {
- break;
- }
- }
- if (isFound)
- {
- break;
- }
- }
- if (isFound)
- {
- break;
- }
- }
- if (!isFound)
- {
- Console.WriteLine("Nothing found");
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР И Environment.Exit(0):
- using System;
- namespace SumAndProduct
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- for (int i = 1; i < 9; i++)
- {
- for (int j = 9; j > i; j--)
- {
- for (int k = 0; k < 9; k++)
- {
- for (int l = 9; l > k; l--)
- {
- if ((i + j + k + l) == i * j * k * l && num % 10 == 5
- || (i * j * k * l / (i + j + k + l)) == 3 && num % 3 == 0)
- {
- Console.WriteLine((i + j + k + l) == i * j * k * l ? $"{i}{j}{k}{l}" : $"{l}{k}{j}{i}");
- Environment.Exit(0);
- }
- }
- }
- }
- }
- Console.WriteLine("Nothing found");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement