Submission #1513445


Source Code Expand

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(long &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

long gcd(long x, long y) {
   return y == 0 ? x : gcd(y, x%y);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long x, y;
      if( scanf("%ld/%ld", &x, &y) < 0 ) exit(0);
      long lower = floor(2.0 * x / y);
      long upper = floor(2.0 * x / y + 2 - 1);
      // long lower = (2 * x + (y - 1)) / y - 1;
      // long upper = (2 * (x + y)) / y - 1;
      bool exist = false;
      if( lower > 2000000000 ) {
         puts("Impossible");
         return;
      }
      for(long n = lower; n <= upper; ++n) {
         if( n < 1 ) continue;
         bool cond = gcd(n, y) * gcd(x, y) % y == 0;
         if( not cond ) continue;
         long ma = n * (y * ((n + 1)) - 2 * (x));
         long mb = 2 * y;
         long m = ma / mb;
         if( ma % mb != 0 ) continue;
         if( not ( 1 <= m and m <= n ) ) continue;
         printf("%ld %ld\n", n, m);
         exist = true;
      }
      if( not exist ) {
         puts("Impossible");
      }
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}

Submission Info

Submission Time
Task C - 平均値太郎の憂鬱 ( The melancholy of Taro Heikinchi )
User spica314
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2514 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 60
Set Name Test Cases
All 00_killer.txt, 00_max.txt, 00_min.txt, 00_min2.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 02_rnd2_00.txt, 02_rnd2_01.txt, 02_rnd2_02.txt, 02_rnd2_03.txt, 02_rnd2_04.txt, 02_rnd2_05.txt, 02_rnd2_06.txt, 02_rnd2_07.txt, 02_rnd2_08.txt, 02_rnd2_09.txt, 02_rnd2_10.txt, 02_rnd2_11.txt, 02_rnd2_12.txt, 02_rnd2_13.txt, 02_rnd2_14.txt, 02_rnd2_15.txt, 02_rnd2_16.txt, 02_rnd2_17.txt, 02_rnd2_18.txt, 02_rnd2_19.txt, 03_smallrnd_00.txt, 03_smallrnd_01.txt, 03_smallrnd_02.txt, 03_smallrnd_03.txt, 03_smallrnd_04.txt, 03_smallrnd_05.txt, 03_smallrnd_06.txt, 03_smallrnd_07.txt, 03_smallrnd_08.txt, 03_smallrnd_09.txt, 04_primes_01.txt, 04_primes_02.txt
Case Name Status Exec Time Memory
00_killer.txt AC 1 ms 256 KB
00_max.txt AC 1 ms 256 KB
00_min.txt AC 1 ms 256 KB
00_min2.txt AC 1 ms 256 KB
00_sample_01.txt AC 1 ms 256 KB
00_sample_02.txt AC 1 ms 256 KB
00_sample_03.txt AC 1 ms 256 KB
00_sample_04.txt AC 1 ms 256 KB
01_rnd_00.txt AC 1 ms 256 KB
01_rnd_01.txt AC 1 ms 256 KB
01_rnd_02.txt AC 1 ms 256 KB
01_rnd_03.txt AC 1 ms 256 KB
01_rnd_04.txt AC 1 ms 256 KB
01_rnd_05.txt AC 1 ms 256 KB
01_rnd_06.txt AC 1 ms 256 KB
01_rnd_07.txt AC 1 ms 256 KB
01_rnd_08.txt AC 1 ms 256 KB
01_rnd_09.txt AC 1 ms 256 KB
01_rnd_10.txt AC 1 ms 256 KB
01_rnd_11.txt AC 1 ms 256 KB
01_rnd_12.txt AC 1 ms 256 KB
01_rnd_13.txt AC 1 ms 256 KB
01_rnd_14.txt AC 1 ms 256 KB
01_rnd_15.txt AC 1 ms 256 KB
01_rnd_16.txt AC 1 ms 256 KB
01_rnd_17.txt AC 1 ms 256 KB
01_rnd_18.txt AC 1 ms 256 KB
01_rnd_19.txt AC 1 ms 256 KB
02_rnd2_00.txt AC 1 ms 256 KB
02_rnd2_01.txt AC 1 ms 256 KB
02_rnd2_02.txt AC 1 ms 256 KB
02_rnd2_03.txt AC 1 ms 256 KB
02_rnd2_04.txt AC 1 ms 256 KB
02_rnd2_05.txt AC 1 ms 256 KB
02_rnd2_06.txt AC 1 ms 256 KB
02_rnd2_07.txt AC 1 ms 256 KB
02_rnd2_08.txt AC 1 ms 256 KB
02_rnd2_09.txt AC 1 ms 256 KB
02_rnd2_10.txt AC 1 ms 256 KB
02_rnd2_11.txt AC 1 ms 256 KB
02_rnd2_12.txt AC 1 ms 256 KB
02_rnd2_13.txt AC 1 ms 256 KB
02_rnd2_14.txt AC 1 ms 256 KB
02_rnd2_15.txt AC 1 ms 256 KB
02_rnd2_16.txt AC 1 ms 256 KB
02_rnd2_17.txt AC 1 ms 256 KB
02_rnd2_18.txt AC 1 ms 256 KB
02_rnd2_19.txt AC 1 ms 256 KB
03_smallrnd_00.txt AC 1 ms 256 KB
03_smallrnd_01.txt AC 1 ms 256 KB
03_smallrnd_02.txt AC 1 ms 256 KB
03_smallrnd_03.txt AC 1 ms 256 KB
03_smallrnd_04.txt AC 1 ms 256 KB
03_smallrnd_05.txt AC 1 ms 256 KB
03_smallrnd_06.txt AC 1 ms 256 KB
03_smallrnd_07.txt AC 1 ms 256 KB
03_smallrnd_08.txt AC 1 ms 256 KB
03_smallrnd_09.txt AC 1 ms 256 KB
04_primes_01.txt AC 1 ms 256 KB
04_primes_02.txt AC 1 ms 256 KB