Codeforces Round #657 (Div. 2) B题 Dubious Cyrpto

m是被除数,a是除数,n的商,b-c是余数。切记,考虑b-c是负数的情况。切记 !切记 !

二话不说上代码:

#include 
#include 
using namespace std;

int main(){
	int t;
	cin >> t;
	while(t--){
		long long l,r,m;
		cin >> l >> r >> m;
		long long a = l,b,c;
		long long u = 10000000000000;
		for(long long i = l;i <= r;i++){
			long long x = m%i;
			if(x<u&&l+x <= r){
				u = x;
				a = i;
				c = l;//ok
		        b = l+u;
			}
			long long y = x-i;
			if(l-y <= r){
				a = i;
				b = l;
				c = l-y;
			}
		}
		if(m<l){
			a = l;
			b = l;
			c = a+b-m;
		}
		cout << a << " " << b << " " << c << endl;
	}
	return 0;
}

你可能感兴趣的:(ACM-ICPC算法,算法)