padamprakash2014's blog

By padamprakash2014, history, 7 months ago, In English,

for the problem http://codeforces.com/contest/914/problem/A

Your code here...
#include "bits/stdc++.h"
     using namespace std;
     const int N = 1e3 + 3;
     const int M = 1e6 + 6;
     int n;
     int arr[N];
     int mark[M];
     int val;
     int main(){
             scanf("%d" , &n);
             val = -M;
             for(int i = 0 ; i * i < M ; ++i)
                {
         mark[i * i] = 1;
            }
            for(int i = 1 ; i <= n ; ++i)
                {
        scanf("%d" , arr + i);  
        if(arr[i] >= 0 && mark[arr[i]]){
       continue;
        }
        val = max(val , arr[i]);
           }
          printf("%d\n" , val);
    }

Also please explain the method of Input for long range of values.. I generally use long long int for such input range. is it good practice??

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

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by padamprakash2014 (previous revision, new revision, compare).

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

He makes a table full of zeros, and marks the square numbers with a 1. Then for each number in the input he can check if it is square by looking if mark[i] is a one.

Why would you use long long int? If you are not programming on a microcontroller or some really ancient device an int will have 32 bits, which is more than enough to store numbers in the range ~-2*10^9 — ~2*10^9.