/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 348.0 KiB
#2 Wrong Answer 1ms 532.0 KiB

Code


/*
 *  Copyright (c) 2025 Parag Kishor Shornob
 *   All rights reserved.
 */
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<long long > vi;
typedef pair<int,int> pii;
 
#define yes "YES\n"
#define no "NO\n"
#define pb push_back
#define pop pop_back
#define fastin ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define input(v) for(auto &i  : v) cin>>i;
#define all(x) (x).begin(),(x).end()
 
char ee = '\n';
void printVec(vector<ll> &a){
    for(auto pp : a) cout<<pp <<" " ;
    cout<<ee;
}
ll power(ll base , ll exp){   
    ll result=1;
    while(exp>0){
       if(exp%2==1){
        result *=base;
       }
       base  *=base ;
       exp/=2;
 
    }
    return result;
 
}
ll cost(ll n ){
    return power(3,n+1)+ n*power(3,n-1);
}
ll base (ll n ){
     ll ans =0 , base =1;
     while(base *3<=n){
        base *=3;
        ans++;
        
     }
    return ans;
}
void  solve(){
   ll n ; cin>>n ;
   ll ans =0;
   while(n>0){
    //ll p = log(n)/log(3);
    ll p = base (n);
    ans+=cost(p);
    n-=power(3,p);
 
   }
   cout<<ans<<ee;
 
}
signed main() {
    fastin; 
    ll tt=1 ; cin>> tt;
    while(tt--) solve();
  
}

Information

Submit By
Type
Submission
Problem
P1002 D. Office Space
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-01 03:20:40
Judged At
2025-09-01 03:20:40
Judged By
Score
0
Total Time
1ms
Peak Memory
532.0 KiB