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;
- using System.Threading.Tasks;
- namespace PageNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int digits = int.Parse(Console.ReadLine());
- int sumOfDigits = 0;
- int currentPage = 0;
- while (true)
- {
- if (currentPage <= 9)
- {
- sumOfDigits++;
- }
- else if(currentPage >=10 && currentPage <= 99)
- {
- sumOfDigits += 2;
- }
- else if (currentPage >= 100 && currentPage <= 999)
- {
- sumOfDigits += 3;
- }
- else if (currentPage >= 1000 && currentPage <= 9999)
- {
- sumOfDigits += 4;
- }
- else if (currentPage >= 10000 && currentPage <= 99999)
- {
- sumOfDigits += 5;
- }
- else if (currentPage >= 100000 && currentPage <= 999999)
- {
- sumOfDigits += 6;
- }
- currentPage++;
- if (sumOfDigits >= digits)
- {
- break;
- }
- }
- Console.WriteLine(currentPage-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement