Kn0wthyself's blog

By Kn0wthyself, 10 months ago, In English

248913591 Here I use directly pow function in cout; so it gives a value which is in power. But when I store the it one integer varible than it gives direct value. so in contest time or problem solving time if we use directly pow function in cout it will gives error. have anyone opinion about this to ignore this problem using pow function directly in cout .

Wrong Solution

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        int a=log2(n);
        int ans=pow(2,a);
        cout<<ans<<endl;
    }
    return 0;
}

Right solution

~~~~~ ~~~~~ #include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n; cin>>n; int a=log2(n); int ans=pow(2,a); cout<<ans<<endl; } return 0; } ~~~~~ ~~~~~

Full text and comments »

Tags pow
  • Vote: I like it
  • -2
  • Vote: I do not like it

By Kn0wthyself, history, 10 months ago, In English

Today I am share my new experience . I am trying to solve a problem in SPOJ. Problem link:https://www.spoj.com/problems/COMDIV/ When I solve this problem using C++ it gives TLE for simple code. For this problem my solving approach was at first find the GCD of two values than from 1 to GCD I use a loop if any number is divided by that than i count it for two time without corner case. But it gives me Time Limited Exceed. I really become astonished to see this. Than just i convert it into c . instead of cin use scanf and instead of cout use printf than it accept the code. Truly it was a bad experience for me in problem solving.

Full text and comments »

  • Vote: I like it
  • -7
  • Vote: I do not like it