Guest User

1. Convert from base-10 to base-N

a guest
Oct 19th, 2016
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace ConsoleApplication9
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. List<BigInteger> nums = new List<BigInteger>();
  15. nums = Console.ReadLine().Split(' ').Select(BigInteger.Parse).ToList() ;
  16. int n = (int)nums[0];
  17. BigInteger number = nums[1];
  18. BigInteger remainder;
  19. string result = null;
  20.  
  21. if (n >= 2 && n <= 10)
  22. {
  23. while (number >0)
  24. {
  25. remainder = number % n;
  26. number /= n;
  27.  
  28. result = remainder.ToString() + result;
  29. }
  30.  
  31. Console.WriteLine(result);
  32. }
  33. else
  34. {
  35. Console.WriteLine(0);
  36. }
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment