fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. bool g( const int a[], int n )
  6. {
  7. int long long sum = 0;
  8. int i = 0;
  9. long long int target = (1<<n)-1;
  10.  
  11. for ( ; i < n && a[i] > 0 ; i++ ) sum += 1<<a[i]-1;
  12.  
  13. return i == n && sum == target;
  14. }
  15.  
  16. int main()
  17. {
  18. const int N = 6;
  19. int t[N] = { 6, 2, 3, 4, 5, 1 };
  20.  
  21. std::cout << std::boolalpha << g( t, N ) << std::endl;
  22. }
  23.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
true