結果

問題 No.1746 Sqrt Integer Segments
ユーザー 👑 p-adicp-adic
提出日時 2023-09-12 09:11:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 26,057 bytes
コンパイル時間 3,805 ms
コンパイル使用メモリ 238,048 KB
実行使用メモリ 22,748 KB
最終ジャッジ日時 2024-06-29 21:55:45
合計ジャッジ時間 8,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 16 ms
8,112 KB
testcase_19 AC 15 ms
8,168 KB
testcase_20 AC 16 ms
8,048 KB
testcase_21 AC 41 ms
7,368 KB
testcase_22 AC 40 ms
7,920 KB
testcase_23 AC 22 ms
7,144 KB
testcase_24 AC 81 ms
8,176 KB
testcase_25 AC 79 ms
8,164 KB
testcase_26 AC 80 ms
8,176 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef DEBUG
  #define _GLIBCXX_DEBUG
  #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ); signal( SIGABRT , &AlertAbort )
  #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , DEBUG_VALUE )
  #define CERR( MESSAGE ) cerr << MESSAGE << endl;
  #define COUT( ANSWER ) cout << "出力: " << ANSWER << endl
  #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " << ( MIN ) << ( ( MIN ) <= A ? "<=" : ">" ) << A << ( A <= ( MAX ) ? "<=" : ">" ) << ( MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) )
  #define AUTO_CHECK bool auto_checked = true; AutoCheck( auto_checked ); if( auto_checked ){ return 0; };
  #define START_WATCH( PROCESS_NAME ) StartWatch( PROCESS_NAME )
  #define STOP_WATCH( HOW_MANY_TIMES ) StopWatch( HOW_MANY_TIMES )
#else
  #pragma GCC optimize ( "O3" )
  #pragma GCC optimize( "unroll-loops" )
  #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
  #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr )
  #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , VALUE )
  #define CERR( MESSAGE ) 
  #define COUT( ANSWER ) cout << ANSWER << "\n"
  #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
  #define AUTO_CHECK
  #define START_WATCH( PROCESS_NAME )
  #define STOP_WATCH( HOW_MANY_TIMES )
#endif
// #define RANDOM_TEST
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) )
#define TYPE_OF( VAR ) decay_t<decltype( VAR )>
#define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE
#define CIN( LL , A ) LL A; cin >> A
#define CIN_ASSERT( A , MIN , MAX ) TYPE_OF( MAX ) A; SET_ASSERT( A , MIN , MAX )
#define GETLINE( A ) string A; getline( cin , A )
#define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ )
#define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- )
#define AUTO_ITR( ARRAY ) auto itr_ ## ARRAY = ARRAY .begin() , end_ ## ARRAY = ARRAY .end()
#define FOR_ITR( ARRAY ) for( AUTO_ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT_ ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES )
#define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS )
#define QUIT goto END_MAIN
#define TEST_CASE_NUM( BOUND ) DEXPR( int , bound_T , BOUND , min( BOUND , 100 ) ); int T = 1; if constexpr( bound_T > 1 ){ SET_ASSERT( T , 1 , bound_T ); }
#define START_MAIN REPEAT( T ){ if constexpr( bound_T > 1 ){ CERR( "testcase " << VARIABLE_FOR_REPEAT_T << ":" ); }
#define FINISH_MAIN QUIT; } END_MAIN: CERR( "" );

#ifdef DEBUG
  inline void AlertAbort( int n ) { CERR( "abort関数が呼ばれました。assertマクロのメッセージが出力されていない場合はオーバーフローの有無を確認をしてください。" ); }
  void AutoCheck( bool& auto_checked );
  void StartWatch( const string& process_name = "nothing" );
  void StopWatch( const int& how_many_times = 1 );
#endif
#if defined( DEBUG ) && defined( RANDOM_TEST )
  ll GetRand( const ll& Rand_min , const ll& Rand_max );
  #define SET_ASSERT( A , MIN , MAX ) CERR( #A << " = " << ( A = GetRand( MIN , MAX ) ) )
  #define RETURN( ANSWER ) if( ( ANSWER ) == guchoku ){ CERR( ( ANSWER ) << " == " << guchoku ); goto END_MAIN; } else { CERR( ( ANSWER ) << " != " << guchoku ); QUIT; }
#else
  #define SET_ASSERT( A , MIN , MAX ) cin >> A; ASSERT( A , MIN , MAX )
  #define RETURN( ANSWER ) COUT( ( ANSWER ) ); QUIT
#endif

// 算術的関数
template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : -a; }
template <typename T> inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); }
inline ll MIN( const ll& a , const ll& b ){ return min( a , b ); }
inline ull MIN( const ull& a , const ull& b ){ return min( a , b ); }
inline ll MAX( const ll& a , const ll& b ){ return max( a , b ); }
inline ull MAX( const ull& a , const ull& b ){ return max( a , b ); }

#define POWER( ANSWER , ARGUMENT , EXPONENT )				\
  static_assert( ! is_same<TYPE_OF( ARGUMENT ),int>::value && ! is_same<TYPE_OF( ARGUMENT ),uint>::value ); \
  TYPE_OF( ARGUMENT ) ANSWER{ 1 };					\
  {									\
    TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT );	\
    TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT );	\
    while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){			\
      if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){			\
	ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER;			\
      }									\
      ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER;	\
      EXPONENT_FOR_SQUARE_FOR_POWER /= 2;				\
    }									\
  }									\

#define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO )		\
  ll ANSWER{ 1 };							\
  {									\
    ll ARGUMENT_FOR_SQUARE_FOR_POWER = ( ( MODULO ) + ( ( ARGUMENT ) % ( MODULO ) ) ) % ( MODULO ); \
    TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT );	\
    while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){			\
      if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){			\
	ANSWER = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \
      }									\
      ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \
      EXPONENT_FOR_SQUARE_FOR_POWER /= 2;				\
    }									\
  }									\

#define FACTORIAL_MOD( ANSWER , ANSWER_INV , INVERSE , MAX_INDEX , CONSTEXPR_LENGTH , MODULO ) \
  static ll ANSWER[CONSTEXPR_LENGTH];					\
  static ll ANSWER_INV[CONSTEXPR_LENGTH];				\
  static ll INVERSE[CONSTEXPR_LENGTH];					\
  {									\
    ll VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1;				\
    ANSWER[0] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL;			\
    FOREQ( i , 1 , MAX_INDEX ){						\
      ANSWER[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= i ) %= ( MODULO ); \
    }									\
    ANSWER_INV[0] = ANSWER_INV[1] = INVERSE[1] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \
    FOREQ( i , 2 , MAX_INDEX ){						\
      ANSWER_INV[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= INVERSE[i] = ( MODULO ) - ( ( ( ( MODULO ) / i ) * INVERSE[ ( MODULO ) % i ] ) % ( MODULO ) ) ) %= ( MODULO ); \
    }									\
  }									\

// 二分探索テンプレート
// EXPRESSIONがANSWERの広義単調関数の時、EXPRESSION >= TARGETの整数解を格納。
#define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , DESIRED_INEQUALITY , TARGET , INEQUALITY_FOR_CHECK , UPDATE_U , UPDATE_L , UPDATE_ANSWER ) \
  static_assert( ! is_same<TYPE_OF( TARGET ),uint>::value && ! is_same<TYPE_OF( TARGET ),ull>::value ); \
  ll ANSWER = MINIMUM;							\
  if( MINIMUM <= MAXIMUM ){						\
    ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM;				\
    ll VARIABLE_FOR_BINARY_SEARCH_U = MAXIMUM;				\
    ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \
    ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH;			\
    while( VARIABLE_FOR_BINARY_SEARCH_L != VARIABLE_FOR_BINARY_SEARCH_U ){ \
      VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( EXPRESSION ) - ( TARGET ); \
      CERR( "二分探索中: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << "-" << TARGET << "=" << VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ); \
      if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH INEQUALITY_FOR_CHECK 0 ){	\
	VARIABLE_FOR_BINARY_SEARCH_U = UPDATE_U;			\
      } else {								\
	VARIABLE_FOR_BINARY_SEARCH_L = UPDATE_L;			\
      }									\
      ANSWER = UPDATE_ANSWER;						\
    }									\
    CERR( "二分探索終了: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << ( EXPRESSION > TARGET ? ">" : EXPRESSION < TARGET ? "<" : "=" ) << TARGET ); \
    CERR( ( EXPRESSION DESIRED_INEQUALITY TARGET ? "二分探索成功" : "二分探索失敗" ) ); \
    assert( EXPRESSION DESIRED_INEQUALITY TARGET );			\
  } else {								\
    CERR( "二分探索失敗: " << MINIMUM << ">" << MAXIMUM );		\
    assert( MINIMUM <= MAXIMUM );					\
  }									\

// 単調増加の時にEXPRESSION >= TARGETの最小解を格納。
#define BS1( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , >= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調増加の時にEXPRESSION <= TARGETの最大解を格納。
#define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , > , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調減少の時にEXPRESSION >= TARGETの最大解を格納。
#define BS3( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , < , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調減少の時にEXPRESSION <= TARGETの最小解を格納。
#define BS4( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , <= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// t以下の値が存在すればその最大値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MaximumLeq( set<T>& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.upper_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; }
// t未満の値が存在すればその最大値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MaximumLt( set<T>& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.lower_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; }
// t以上の値が存在すればその最小値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MinimumGeq( set<T>& S , const T& t ) { return S.lower_bound( t ); }
// tより大きい値が存在すればその最小値のiterator、存在しなければend()を返す。
template <typename T> inline typename set<T>::iterator MinimumGt( set<T>& S , const T& t ) { return S.upper_bound( t ); }

// データ構造用関数
template <typename T> inline T add( const T& t0 , const T& t1 ) { return t0 + t1; }
template <typename T> inline const T& zero() { static const T z = 0; return z; }
template <typename T> inline T add_inv( const T& t ) { return -t; }
template <typename T> inline T multiply( const T& t0 , const T& t1 ) { return t0 * t1; }
template <typename T> inline const T& one() { static const T o = 1; return o; }
template <typename T> inline T id( const T& v ) { return v; }

// グリッド問題用関数
int H , W , H_minus , W_minus , HW;
inline pair<int,int> EnumHW( const int& v ) { return { v / W , v % W }; }
inline int EnumHW_inv( const int& h , const int& w ) { return h * W + w; }
const string direction[4] = {"U","R","D","L"};
// (i,j)->(k,h)の方向番号を取得
inline int DirectionNumberOnGrid( const int& i , const int& j , const int& k , const int& h ){return i<k?2:i>k?0:j<h?1:j>h?3:(assert(false),-1);}
// v->wの方向番号を取得
inline int DirectionNumberOnGrid( const int& v , const int& w ){auto [i,j]=EnumHW(v);auto [k,h]=EnumHW(w);return DirectionNumberOnGrid(i,j,k,h);}
// 方向番号の反転U<->D、R<->L
inline int ReverseDirectionNumberOnGrid( const int& n ){assert(0<=n&&n<4);return(n+2)%4;}

// 圧縮用
#define TE template
#define TY typename
#define US using
#define ST static
#define IN inline
#define CL class
#define PU public
#define OP operator
#define CE constexpr
#define CO const
#define NE noexcept
#define RE return 
#define WH while
#define VO void
#define VE vector
#define LI list
#define BE begin
#define EN end
#define SZ size
#define MO move
#define TH this
#define CRI CO int&
#define CRUI CO uint&
#define CRL CO ll&

// 入力の範囲内で要件
// (1) (T,m_T:T^2->T,i_T:T->T)が群である。
// が成り立つ場合のみサポート。(単位元はテンプレート引数に渡さなくてよい)
template <typename T , T m_T(const T&,const T&) , T i_T(const T&) , int size_max>
class CumulativeProd_Body
{

protected:
  int m_size;
  T m_a[size_max];
  T m_a_reverse[size_max];

public:
  inline CumulativeProd_Body( const int& size );

  // 0 <= i,j < m_sizeの場合のみサポート。
  // iからへのpathがi=v_0->...->v_k=jの時m_a[v_0]...m_a[v_k]を
  // Prodや逆順のProdに関して計算する。
  inline T PathProd( const int& i , const int& j );

private:
  virtual int Parent( const int& i ) = 0;
  virtual int LCA( const int& i , const int& j ) = 0;

};


// 通常の配列上の累積積。
// テンプレート引数に単位元e_T:1->Tも渡す。

// 配列による初期化O(size)

// 右区間積取得O(1)
// 左区間積取得O(1)

// 区間積が単位元である区間の数え上げO(size log size)
// 区間積が単位元である区間の列挙O(size log size + 区間数)
template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max>
class CumulativeProd :
  public CumulativeProd_Body<T,m_T,i_T,size_max>
{

public:
  inline CumulativeProd( const T ( &a )[size_max] , const int& size );

  // 0 <= iかつi-1 <= j < m_sizeの場合のみサポート。
  // m_a[i]...m_a[j]をm_Tに関してで計算する。
  inline T RightProd( const int& i , const int& j );
  // m_a[j]...m_a[i]をm_Tに関して計算する。
  inline T LeftProd( const int& i , const int& j );

  // 区間積がe_T()と等しい区間の個数を計算する。
  ll CountUnitProdRange();
  // 区間積がe_T()と等しい区間を列挙する。
  list<pair<int,int> > UnitProdRange();
  
private:
  inline int Parent( const int& i );
  inline int LCA( const int& i , const int& j );

};

template <typename T , T m_T(const T&,const T&) , T i_T(const T&) , int size_max> inline CumulativeProd_Body<T,m_T,i_T,size_max>::CumulativeProd_Body( const int& size ) : m_size( size ) , m_a() , m_a_reverse() { assert( size <= size_max ); }

template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max> inline CumulativeProd<T,m_T,e_T,i_T,size_max>::CumulativeProd( const T ( &a )[size_max] , const int& size ) : CumulativeProd_Body<T,m_T,i_T,size_max>( size )
{

  using base = CumulativeProd_Body<T,m_T,i_T,size_max>;
  T temp , temp_reverse;
  base::m_a[0] = base::m_a_reverse[0] = temp = temp_reverse = a[0];

  for( int i = 1 ; i < size ; i++ ){

    base::m_a[i] = temp = m_T( temp , a[i] );
    base::m_a_reverse[i] = temp_reverse = m_T( a[i] , temp_reverse );

  }

}

template <typename T , T m_T(const T&,const T&) , T i_T(const T&) , int size_max> inline  T CumulativeProd_Body<T,m_T,i_T,size_max>::PathProd( const int& i , const int& j ) { assert( 0 <= i && i < m_size && 0 <= j && j < m_size ); const int k = LCA( i , j ); return m_T( m_T( m_a_reverse[i] , i_T( m_a_reverse[k] ) ) , k == 0 ? m_a[j] : m_T( i_T( m_a[Parent( k ) ] ) , m_a[j] )); }

template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max> inline T CumulativeProd<T,m_T,e_T,i_T,size_max>::RightProd( const int& i , const int& j )
{
  
  assert( i - 1 <= j );
  using base = CumulativeProd_Body<T,m_T,i_T,size_max>;
  return i <= j ? i == 0 ? base::m_a[j] : m_T( i_T( base::m_a[i-1] ) , base::m_a[j] ) : e_T();

}

template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max> inline T CumulativeProd<T,m_T,e_T,i_T,size_max>::LeftProd( const int& i , const int& j )
{
  
  assert( i - 1 <= j );
  using base = CumulativeProd_Body<T,m_T,i_T,size_max>;
  return i <= j ? i == 0 ? base::m_a_reverse[j] : m_T( base::m_a_reverse[j] , i_T( base::m_a_reverse[i - 1] ) ) : e_T();

}

template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max> ll CumulativeProd<T,m_T,e_T,i_T,size_max>::CountUnitProdRange()
{

  using base = CumulativeProd_Body<T,m_T,i_T,size_max>;
  map<T,ll> f{};
  f[e_T()]++;

  for( int i = 0 ; i < base::m_size ; i++ ){

    f[base::m_a[i]]++;

  }

  ll answer = 0;

  for( auto itr_f = f.begin() , end_f = f.end() ; itr_f != end_f ; itr_f++ ){

    const ll& num = itr_f->second;
    answer += num * ( num - 1 ) / 2;

  }

  return answer;

}

template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max> list<pair<int,int> > CumulativeProd<T,m_T,e_T,i_T,size_max>::UnitProdRange()
{

  using base = CumulativeProd_Body<T,m_T,i_T,size_max>;
  map<T,list<int> > f{};
  f[e_T()].push_back( -1 );

  for( int i = 0 ; i < base::m_size ; i++ ){

    f[base::m_a[i]].push_back( i );

  }

  list<pair<int,int> > answer{};

  for( auto itr_f = f.begin() , end_f = f.end() ; itr_f != end_f ; itr_f++ ){

    const auto& a = itr_f->second;
    
    for( auto itr_a_L = a.begin() , end_a = a.end() ; itr_a_L != end_a ; itr_a_L++ ){

      const int i = *itr_a_L + 1;
      auto itr_a_R = itr_a_R;
      itr_a_R++;

      while( itr_a_R != end_a ){

	answer.push_back( i , *itr_a_R );

      }

    }

  }

  return answer;

}

template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max> inline int CumulativeProd<T,m_T,e_T,i_T,size_max>::Parent( const int& i ) { return i - 1; }

template <typename T , T m_T(const T&,const T&) , const T& e_T() , T i_T(const T&) , int size_max> inline int CumulativeProd<T,m_T,e_T,i_T,size_max>::LCA( const int& i , const int& j ) { return min( i , j ); }

template <typename T>
class ZobristHashBody
{

protected:
  ull m_hash;

public:
  inline ZobristHashBody( const ull& hash );

  ull Encode( const set<T>& S );
  inline ull Encode( const list<T>& S , const bool& non_overlapping = false );
  template <int length_max> inline ull Encode( const T ( &a )[length_max] , const int& length , const bool& non_overlapping = false );

  inline ull SymmetricDifference( const ull& code0 , const ull& code1 );
  inline ull Add( set<T>& S , const ull& code , const T& t );
  inline ull Erase( set<T>& S , const ull& code , const T& t );
  inline ull AddErase( const ull& code , const T& t );
  
private:
  ull OverlappingEncode( const list<T>& S );
  template <int length_max> ull OverlappingEncode( const T ( &a )[length_max] , const int& length );
  ull NonOverlappingEncode( const list<T>& S );
  template <int length_max> ull NonOverlappingEncode( const T ( &a )[length_max] , const int& length );
  virtual ull Hash( const T& t ) = 0;

};

// 集合のコードO(要素数)
// リストの像のコードO(要素数 log 要素数)(無重複保証畤はO(要素数))
// 配列の像のコードO(要素数 log 要素数)(無重複保証畤はO(要素数))

// 集合の対称差O(1)
// 要素追加O(log要素数)
// 要素削除O(log要素数)
// 要素がある場合は削除、ない場合は追加O(1)
class ZobristHash :
  public ZobristHashBody<ull>
{

public:
  inline ZobristHash( const ull& hash = 14177381365537266759ULL );
  
private:
  inline ull Hash( const ull& t );

};

// 集合のコードO(要素数 log_size)
// リストの像のコードO(要素数(log 要素数)(log size))(無重複保証畤はO(要素数 log size))
// 配列の像のコードO(要素数(log 要素数)(log size))(無重複保証畤はO(要素数 log size))

// 集合の対称差O(1)
// 要素追加O((log要素数)(log size))
// 要素削除O((log要素数)(log size))
// 要素がある場合は削除、ない場合は追加O(log size)
template <typename T>
class MemorisationZobristHash :
  public ZobristHashBody<T>
{

private:
  map<T,ull> m_f;
  
public:
  inline MemorisationZobristHash( const ull& hash = 14177381365537266759ULL );
  
private:
  inline ull Hash( const T& t );

};

// 集合のコードO(要素数)
// リストの像のコードO(要素数 log 要素数)(無重複保証畤はO(要素数))
// 配列の像のコードO(要素数 log 要素数)(無重複保証畤はO(要素数))

// 集合の対称差O(1)
// 要素追加O(log要素数)
// 要素削除O(log要素数)
// 要素がある場合は削除、ない場合は追加O(1)
template <typename T , int enum_T_inv(const T&)>
class EnumerationZobristHash :
  public ZobristHashBody<T>
{

public:
  inline EnumerationZobristHash( const ull& hash = 14177381365537266759ULL );
  
private:
  inline ull Hash( const T& t );

};

template <typename T> inline ZobristHashBody<T>::ZobristHashBody( const ull& hash ) : m_hash( hash ) {}
inline ZobristHash::ZobristHash( const ull& hash ) : ZobristHashBody<ull>( hash ) {}
template <typename T> inline MemorisationZobristHash<T>::MemorisationZobristHash( const ull& hash ) : ZobristHashBody<T>( hash ) {}
template <typename T , int enum_T_inv(const T&)> inline EnumerationZobristHash<T,enum_T_inv>::EnumerationZobristHash( const ull& hash ) : ZobristHashBody<T>( hash ) {}


template <typename T> ull ZobristHashBody<T>::Encode( const set<T>& S )
{

  ull answer = 0;

  for( auto itr = S.begin() , end = S.end() ; itr != end ; itr++ ){

    answer ^= Hash( *itr );

  }

  return answer;

}

template <typename T> inline ull ZobristHashBody<T>::Encode( const list<T>& S , const bool& non_overlapping ) { return non_overlapping ? NonOverlappingEncode( S ) : OverlappingEncode( S ); }

template <typename T> template <int length_max> inline ull ZobristHashBody<T>::Encode( const T ( &a )[length_max] , const int& length , const bool& non_overlapping ) { return non_overlapping ? NonOverlappingEncode( a , length ) : OverlappingEncode( a , length ); }

template <typename T> ull ZobristHashBody<T>::OverlappingEncode( const list<T>& S )
{

  set<T> S_set{};

  for( auto itr = S.begin() , end = S.end() ; itr != end ; itr++ ){

    S_set.insert( *itr );

  }

  return Encode( S_set );

}

template <typename T> template <int length_max> ull ZobristHashBody<T>::OverlappingEncode( const T ( &a )[length_max] , const int& length )
{

  set<T> S_set{};

  for( int i = 0 ; i < length ; i++ ){

    S_set.insert( a[i] );

  }

  return Encode( S_set );

}

template <typename T> ull ZobristHashBody<T>::NonOverlappingEncode( const list<T>& S )
{

  ull answer = 0;

  for( auto itr = S.begin() , end = S.end() ; itr != end ; itr++ ){

    answer ^= Hash( *itr );

  }

  return answer;
  
}

template <typename T> template <int length_max> ull ZobristHashBody<T>::NonOverlappingEncode( const T ( &a )[length_max] , const int& length )
{

  ull answer = 0;

  for( int i = 0 ; i < length ; i++ ){

    answer ^= Hash( a[i] );

  }

  return answer;

}

template <typename T> inline ull ZobristHashBody<T>::SymmetricDifference( const ull& code0 , const ull& code1 ) { return code0 ^ code1; }
template <typename T> inline ull ZobristHashBody<T>::Add( set<T>& S , const ull& code , const T& t ) { return S.count( t ) == 0 ? ( S.insert( t ) , code ^ Hash( t ) ) : code; }
template <typename T> inline ull ZobristHashBody<T>::Erase( set<T>& S , const ull& code , const T& t ) { return S.count( t ) == 0 ? code : ( S.erase( t ) , code ^ Hash( t ) ); }
template <typename T> inline ull ZobristHashBody<T>::AddErase( const ull& code , const T& t ){ return code ^ Hash( t ); }

inline ull ZobristHash::Hash( const ull& t ) { return t * ZobristHashBody<ull>::m_hash; }
template <typename T> inline ull MemorisationZobristHash<T>::Hash( const T& t ) { if( m_f.count( t ) == 0 ){ const ull size = m_f.size(); return m_f[t] = size * ZobristHashBody<ull>::m_hash; } return m_f[t]; }
template <typename T , int enum_T_inv(const T&)> inline ull EnumerationZobristHash<T,enum_T_inv>::Hash( const T& t ) { return enum_T_inv( t ) * ZobristHashBody<T>::m_hash; }

TE <TY INT,INT val_limit,int LE_max = val_limit>CL PrimeEnumeration{PU:INT m_val[LE_max];int m_LE;CE PrimeEnumeration();};TE <TY INT,INT val_limit,int LE_max>CE PrimeEnumeration<INT,val_limit,LE_max>::PrimeEnumeration():m_val(),m_LE(0){bool is_comp[val_limit] ={};for(INT i = 2;i < val_limit;i++){if(is_comp[i] == false){INT j = i;WH((j += i) < val_limit){is_comp[j] = true;}m_val[m_LE++] = i;if(m_LE >= LE_max){break;}}}}TE <TY INT,INT val_limit,int LE_max>VO SetPrimeFactorisation(CO PrimeEnumeration<INT,val_limit,LE_max>& prime,CO INT& n,VE<INT>& P,VE<INT>& EX){INT n_copy = n;int i = 0;WH(i < prime.m_LE){CO INT& p = prime.m_val[i];if(p * p > n_copy){break;}if(n_copy % p == 0){P.push_back(p);EX.push_back(1);INT& EX_back = EX.back();n_copy /= p;WH(n_copy % p == 0){EX_back++;n_copy /= p;}}i++;}if(n_copy != 1){P.push_back(n_copy);EX.push_back(1);}RE;}

// データ構造使用畤のNの上限
inline DEXPR( int , bound_N , 200000 , 100 ); // 0が5個

inline ull xor_add( const ull& t0 , const ull& t1 ){ return t0 ^ t1; }

int main()
{
  UNTIE;
  AUTO_CHECK;
  TEST_CASE_NUM( 1 );
  START_MAIN;

  constexpr PrimeEnumeration<int,1000> pe{};
  // ZobristHash zh{};
  MemorisationZobristHash<ull> zh{};
  CIN( int , N );
  
  // ll A[N];
  ull code_A[bound_N]; // 関数(コンストラクタ)の引数に使う。
  FOR( i , 0 , N ){
    CIN( int , Ai );
    vector<int> P;
    vector<int> exponent;
    SetPrimeFactorisation( pe , Ai , P , exponent );
    int size = P.size();
    ull& code_Ai = code_A[i] = 0;
    FOR( i , 0 , size ){
      code_Ai = exponent[i] % 2 == 0 ? code_Ai : zh.AddErase( code_Ai , P[i] );
    }
  }

  CumulativeProd<ull,xor_add,zero,id,bound_N> cp{ code_A , N };
  RETURN( cp.CountUnitProdRange() );

  FINISH_MAIN;
}
0