Language: C++

import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;


string[] calc(int p, int q, RedBlackTree!int s) {
	auto r = p%q;
	if(r == 0){
		s.clear();
		return [to!string(p/q), ""];
	}
	if(r in s) {
		s.clear();
		s.insert(r);
		return [to!string(p/q), "^"];
	}
	s.insert(r);
	auto ret = calc(r*10, q, s);

	ret[0] = to!string(p/q) ~ ret[0];
	if(r in s)
		s.clear();
	if(s.empty())
		ret[1] = " " ~ ret[1];
	else
		ret[1] = "^" ~ ret[1];
	return ret;
}

void main() {
	auto s = readln().strip().split();
	while(!stdin.eof()) {
		int p = to!int(s[0]);
		int q = to!int(s[1]);
		auto ans = calc(p*10, q, redBlackTree!int());
		writeln(ans[0]);
		if(ans[1].back == '^')
			writeln(ans[1]);

		s = readln().strip().split();
	}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import std.stdio;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import std.algorithm;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import std.string;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import std.range;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import std.array;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import std.conv;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import std.complex;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import std.math;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: 'import' does not name a type
    9 | import std.ascii;
      | ^~~~~~
a.cc:9:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:10:1: error: 'import' does not name a type
   10 | import std.bigint;
      | ^~~~~~
a.cc:10:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:11:1: error: 'import' does not name a type
   11 | import std.container;
      | ^~~~~~
a.cc:11:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:14:1: error: 'string' does not name a type
   14 | string[] calc(int p, int q, RedBlackTree!int s) {
      | ^~~~~~
a.cc:38:1: error: '::main' must return 'int'
   38 | void main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:39:18: error: 'readln' was not declared in this scope
   39 |         auto s = readln().strip().split();
      |                  ^~~~~~
a.cc:40:16: error: 'stdin' was not declared in this scope
   40 |         while(!stdin.eof()) {
      |                ^~~~~
a.cc:1:1: note: 'stdin' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | import std.stdio;
a.cc:41:25: error: 'to' was not declared in this scope
   41 |                 int p = to!int(s[0]);
      |                         ^~
a.cc:43:42: error: 'redBlackTree' was not declared in this scope
   43 |                 auto ans = calc(p*10, q, redBlackTree!int());
      |                                          ^~~~~~~~~~~~
a.cc:43:28: error: 'calc' was not declared in this scope
   43 |                 auto ans = calc(p*10, q, redBlackTree!int());
      |                            ^~~~
a.cc:44:17: error: 'writeln' was not declared in this scope
   44 |                 writeln(ans[0]);
      |                 ^~~~~~~