trouble with algorithm
Posted
by rebel_UA
on Stack Overflow
See other posts from Stack Overflow
or by rebel_UA
Published on 2010-04-02T17:14:52Z
Indexed on
2010/04/02
17:23 UTC
Read the original article
Hit count: 503
David likes number of estimates with base "k" and not a multiple(a%2!=0) of the number of zeros at the end. Set system and the number of the order and print it
I need to optimi this algoritm:
class David{
private:
int k;
public:
David();
David(int);
int operator[] (int);
};
David::David(){
k=10;
};
David::David(int k){
this->k=k;
}
int David::operator[] (int n){
int q;
int p;
int i=1;
for(int r=0;r<n;i++){
q=0;
p=i;
for(;;){
if(p%k)
break;
if(p==0)
break;
++q;
p/=k;
}
if(q%2){
r++;
}
}
return i-1;
}
© Stack Overflow or respective owner