-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Sum_of_Two_Numbers.cpp
59 lines (44 loc) · 1.02 KB
/
B_Sum_of_Two_Numbers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Mohit Verma "mohitvdx"
// problem:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;
int digitSum(int a){
int sum=0;
while(a>0){
sum = sum + a%10;
a/=10;
}
return sum;
}
void solve(){
int n; cin>>n;
int x,y;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // gets a random number with the time as seed
uniform_int_distribution<int> dist(0, n ); //sets equal random probability
// int co=0;
while (true){
//apparently randomizing this converges faster
x=dist(rng);
y=n-x;
// co++;
int x1 = digitSum(x);
int y1 = digitSum(y);
if(abs(x1-y1)<=1){
// cout<<"tries needed"<<co<<'\n';
cout<<x<<" "<<y<<'\n';
return;
}
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(NULL); // fast IO
int t; cin>>t;
while(t--){
solve();
}
}
/*
*/