1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include <iostream>
#include <vector>
using namespace std;
int jegop(int a, int b)
{
int i,c;
c=a;
if( b ==0 ) return 1;
for( i = 0 ; i < b - 1 ; i++ ){
c = c * a;
}
return c;
}
int main (int argc, const char * argv[])
{
int num =0;
int n;
int x= 999999999;
int test;
cin >> n;
for( int i=0 ; i < n ; i++){
cin >> x;
num=0;
while( (jegop(10,num) < x) && x <= 999999999){
//cout << "loading..."<<endl;
num++;
}
if ( num ==0 ) {
//cout <<"1->"<<num<<endl;
cout << x <<endl;
}
if( num != 0 && x >100 ) {
//cout <<"2->"<<num<<endl;
//cout <<"here " << num <<endl;
for( int i= int(jegop(10,num)/x) ; i > 0 ; i--){
//cout <<"first i->"<< i <<endl;
if( (jegop(10,num) % i)== 0 && (jegop(10,num)/i)% (i-1) == 0 ) {
//cout <<"important->" <<jegop(10,num) <<endl;
int k=0;
// cout << " num->" <<num<<endl;
int numtemp= num-3;
for( int y=numtemp ; y>=0 ; y--){
//cout << "Y: "<< y <<endl;
k += jegop(10,y) * 5;
//cout <<"result" << jegop(10,0) <<endl;
}
//cout <<"k->"<< k <<endl;
// cout <<" i->"<<i <<endl;
//if((jegop(10,num)/i)-x < ((jegop(10,num-1)/2)-k)) {
if(x-((x/jegop(10,num-1))*jegop(10,num-1)) < ((jegop(10,num-1)/2)-k)) {
// cout << " first loop..." <<endl;
cout << (jegop(10,num)/i)/2-(((jegop(10,num)/i)/2) % jegop(10,num-1))<<endl;
break;
}
else {
///cout << "second loop.." <<endl;
cout << (jegop(10,num) /i) - ( (jegop(10,num) /i) % jegop(10,num-1)) <<endl ;
break;
}
}
}
}else if(num != 0 && x <100 && x> 9 && x !=0){
if( x/ 10 >=4 && x%10 >=5) {
// cout <<"third"<<endl ;
cout << ((x/10)+1)*10<<endl;
}else{
//cout << "fourth..."<<endl;
if( x%10 >=5 ) cout << (x/10)*10*2<<endl;
else{cout << (x/10)*10<<endl;}
}
}else if(x <10 && x !=0 ) cout << x <<endl;
}
}
|