Created
May 11, 2016 12:40
-
-
Save quangnle/31b84331ae3de42b5e8a5bc3eb90fa72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Tuenti11 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var lines = File.ReadAllLines("submitInput.txt"); | |
var nCount = Convert.ToUInt32(lines[0]); | |
var result = ""; | |
for (int i = 1; i <= nCount; i++) | |
{ | |
var arr = lines[i].Split(' '); | |
var m = Convert.ToUInt64(arr[0]); | |
var n = Convert.ToUInt64(arr[1]); | |
var k = Convert.ToUInt64(arr[2]); | |
var r = Solve(m,n,k); | |
var rst = r == UInt64.MaxValue ? "IMPOSSIBLE" : r.ToString(); | |
result += "Case #" + i.ToString() + ": " + rst + "\n"; | |
} | |
File.WriteAllText("submitOutput.txt", result); | |
} | |
static UInt64 Solve(UInt64 m, UInt64 n, UInt64 k) | |
{ | |
if (k % n != 0) return UInt64.MaxValue; | |
if (n * m > k) return UInt64.MaxValue; | |
k = k / n - m + 1; | |
if (k < 0) return UInt64.MaxValue; | |
UInt64 count = 0; | |
while (k != 0) | |
{ | |
if (k % 2 == 1) | |
{ | |
k = k - 1; | |
//count += 1; | |
} | |
else k = k / 2; | |
count++; | |
} | |
return (count > 0)? (count - 1): 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment