1433A - Boring Apartments - CodeForces Solution


implementation math *800

Please click on ads to support us..

Python Code:

t1=int(input())
for i in range(t1):
    x=str(input())
    if len(x)<4:
        p=int(x[-1])-1
        l=(p*10)
        if len(x)==1:
            l+=1
        if len(x)==2:
            l+=3
        if len(x)==3:
            l+=6
        print(l)
    else:
        p=int(x[-1])
        l=p*10
        print(l)

C++ Code:

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

void solve(vector<int>& v)
{
    for(int i=1;i<=9;i++)
    {
        int n=i;
        while(n<=10000)
        {
            v.push_back(n);
            n*=10;
            n+=i;
        }
    }
}

//length of number
 
int countDigit(int n) {
  return floor(log10(n) + 1);
}
 
int main() {
	
    //pre array
	vector<int> v;
	solve(v);
	
// 	for(int i=0;i<v.size();i++)
// 	cout<<v[i]<<endl;
    
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        
        int count=0;
        int i=0;
        for(i;v[i]!=n;i++){
        // {   cout<<v[i]<<" ";
        //     cout<<"ans"<<endl;
            count+=countDigit(v[i]);
        }
        
        if(v[i]==n)
        count+=countDigit(v[i]);
        
        // cout<<endl;
        cout<<count<<endl;
    }
    
	return 0;
}


Comments

Submit
0 Comments
More Questions

1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push