Advertisement
immanual1

DoubeSquares

Oct 10th, 2022
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long int solve(long long int n){
  4.     unordered_set<int>us;
  5.     for(int i=0;i<=sqrt(n);i++){
  6.        
  7.         long long int square=i*i;
  8.         long long int diff=n-square;
  9.         long long int sqrtDiff=sqrt(diff);
  10.         if(sqrtDiff*sqrtDiff==diff){
  11.                 us.insert(i+sqrtDiff);
  12.         }
  13.     }
  14.     return us.size();
  15.    
  16. }
  17. int main() {
  18.    
  19.     int t,i=1;
  20.     cin>>t;
  21.     while(t--){
  22.         long long int n;
  23.         cin>>n;
  24.         cout<<"Case #"<<i<<": "<<solve(n)<<endl;
  25.         i++;
  26.     }
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement