結果

問題 No.2125 Inverse Sum
ユーザー 👑 p-adicp-adic
提出日時 2022-11-18 22:59:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,903 bytes
コンパイル時間 3,123 ms
コンパイル使用メモリ 204,356 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-20 07:57:43
合計ジャッジ時間 4,414 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 WA -
testcase_06 AC 3 ms
4,372 KB
testcase_07 AC 3 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 2 ms
4,372 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

using ll = long long;

#define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type
#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) 
#define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE 
#define CIN( LL , A ) LL A; cin >> A 
#define ASSERT( A , MIN , MAX ) assert( MIN <= A && A <= MAX ) 
#define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) 
#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 QUIT return 0 
#define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT 

class NM
{
public :
  ll m_N;
  ll m_M;
  inline NM( const ll& N = 0 , const ll& M = 0 ) : m_N( N ) , m_M( M ) {};
};

inline bool operator<( const NM& NM0 , const NM& NM1 ) { return NM0.m_N < NM1.m_N; }

int main()
{
  CEXPR( ll , bound_PQ , 1000000000 );
  CIN_ASSERT( P , 1 , bound_PQ );
  CIN_ASSERT( Q , 1 , bound_PQ );
  CEXPR( ll , rQ , 31622 );
  NM answer[rQ];
  // N = ab , M = bc , b = gcd( N , M )
  // 1/N + 1/M = (a+c) / abc
  // ac | Q
  ll b , c , N , M;
  int T = 0;
  FOREQ( a , 1 , Q ){
    if( a * a > Q ){
      break;
    }
    if( Q % a == 0 ){
      c = Q / a;
      b = ( ( ( ( a + c ) * Q ) / P ) / a ) / c;
      if( ( a + c ) * Q == a * b * c * P ){
	N = a * b;
	M = b * c;
	if( N > 0 && M > 0 ){
	  answer[T] = NM( N , M );
	  T++;
	  if( N != M ){
	    answer[T] = NM( M , N );
	    T++;
	  }
	}
      }
    }
  }
  cout << T << "\n";
  sort( answer , answer + T );
  FOR( t , 0 , T ){
    NM& NMt = answer[t];
    cout << NMt.m_N << " " << NMt.m_M << "\n";
  }
  QUIT;
}
0