Блог пользователя Kn0wthyself

Автор Kn0wthyself, 10 месяцев назад, По-английски

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; } ~~~~~ ~~~~~

Полный текст и комментарии »

Теги pow
  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

Автор Kn0wthyself, история, 10 месяцев назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -7
  • Проголосовать: не нравится