1679A - AvtoBus - CodeForces Solution


brute force greedy math number theory *900

Please click on ads to support us..

Python Code:

def test():
    n=int(input())
    if(n%2==1 or n<4):
        print(-1)
        return
    n=n//2
    print((n+2)//3,end=" ")
    print(n//2)
    return
T=int(input())
for i in range(T):
    test()

C++ Code:

#include <bits/stdc++.h>

using namespace std;

long long t, n;
int const maxn = 400000;
long long const q = 10e8 + 7;
int a[maxn];

void solve()
{
	cin >> n;
	if (n < 4) cout << -1 << endl;
	else {
		if (n%2!=0) cout << -1 << endl;
		else {
			if (n%6==0) {
				cout << n/6 << " ";
				if (n%4==0) cout << n/4 << endl;
				else cout << (n - 6)/4 + 1 << endl;
			}
			if (n%6==2) {
				cout << (n - 8)/6 + 2 << " ";
				if (n%4==0) cout << n/4 << endl;
				else cout << (n - 6)/4 + 1 << endl;
			}
			if (n%6==4) {
				cout << (n - 4)/6 + 1 << " ";
				if (n%4==0) cout << n/4 << endl;
				else cout << (n - 6)/4 + 1 << endl;
			}
		}
	}
}

int main()
{
	cin >> t;
	while (t--) {
		solve();
	}
}


Comments

Submit
0 Comments
More Questions

1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100
488A - Giga Tower
14A - Letter
1150A - Stock Arbitraging
1552A - Subsequence Permutation
1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You