// This file is a "Hello, world!" in C++ language by GCC for wandbox. #include #include using namespace std; int main() { int T; cin >> T; while (T-->0) { int N, A, B; cin >> N >> A >> B; long long ans=0; { int top=N-A; int bottom=A-(A-N%A)%A; ans+=(long long)((top-bottom)/A+1)*(top+bottom)/2; } { int top=N-B; int bottom=B-(B-N%B)%B; ans+=(long long)((top-bottom)/B+1)*(top+bottom)/2; } int i=1; while (i<=N/A) { int k=(N-A*i)/B; int ni=(N-B*k)/A+1; ans-=(long long)k*(ni-i); i=ni; } cout << ans << endl; } } // GCC reference: // https://gcc.gnu.org/ // C++ language references: // https://cppreference.com/ // https://isocpp.org/ // http://www.open-std.org/jtc1/sc22/wg21/ // Boost libraries references: // https://www.boost.org/doc/