4

Something wrong with my solution to problem T-primes(230-B)

 2 years ago
source link: http://codeforces.com/blog/entry/96744
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Something wrong with my solution to problem T-primes(230-B)

My submission(134677199) gets Wrong answer on test 1, but everything is right in my compiler. The most interesting part is when I choose GNU C++20 (64) as a submission language it gets Wrong answer on test 8(134677424). My code:

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool primelikefunc(ll a){
    
    for(ll i = 2;i*i<=a;i++){
        if(a%i==0) return false;
    }
    return true;
}
 
int main(){
    ll t,n;
    cin>>t;
    while(t--){
        cin>>n;
        if(sqrt(n)*sqrt(n)==n&&primelikefunc(sqrt(n))==true&&n!=1){
            cout<<"YES"<<'\n';
        }
        else{
            cout<<"NO"<<'\n';
        }
    }
}    

UPD: Actually, not everything in my code was correct. It was false when I entered 11, because I didn't typecast sqrt(n) to long long. After typecasting I got TLE on test 63 and I fixed this issue adding ios_base::sync_with_stdio(false); cin.tie(0); to my code. My accepted code:


#include<bits/stdc++.h> using namespace std; using ll = long long; bool primelikefunc(ll a){ for(ll i = 2;i*i<=a;i++){ if(a%i==0) return false; } return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ll t,n; cin>>t; while(t--){ cin>>n; if((ll)sqrt(n)*(ll)sqrt(n)==n&&primelikefunc((ll)(sqrt(n)))==true&&n!=1){ cout<<"YES"<<'\n'; } else{ cout<<"NO"<<'\n'; } } }

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK