-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuarkPairChallenge.cs
More file actions
54 lines (45 loc) · 1.36 KB
/
QuarkPairChallenge.cs
File metadata and controls
54 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// https://www.sololearn.com/Discuss/622449/?ref=app
namespace SoloLearn
{
class Program
{
static void Main(string[] zephyr_koo)
{
var input1 = Console.ReadLine();
var input2 = Console.ReadLine();
int num1, num2;
if (Int32.TryParse(input1, out num1) && Int32.TryParse(input2, out num2) && IsQuarkPair(num1, num2))
{
Console.WriteLine("Yass we have found a Quark Pair! (^__^)Y");
}
else
{
Console.WriteLine("Nope. (x__x)");
}
}
static bool IsQuarkPair(int num1, int num2)
{
return GetQuarkNumber(num1) == GetQuarkNumber(num2);
}
static int GetQuarkNumber(int num)
{
return num * GetCountOfTwo(num);
}
static int GetCountOfTwo(int num)
{
return Convert.ToString(num, 2).Count(c => c == '1');
/*
int count = 0;
for (uint currentPow = 1; currentPow != 0; currentPow <<= 1)
{
if ((currentPow & num) != 0) count++;
}
return count;*/
}
}
}