fork download
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. signed main(){
  5. int n;
  6. double p;
  7. cin >> n >> p;
  8. for(int k = 0; k <= 10000;++k){
  9. int c1 = k*(k-1)*(k-2)/6;
  10. int c2 = k*(k-1)*(n-k)/2;
  11. int c3 = k*(n-k)*(n-k-1)/2;
  12. int c4 = (n-k)*(n-k-1)*(n-k-2)/6;
  13. double ans = 1.0 *(c1+c2+0.5*c3+0*c4)/(c1+c2+c3+c4);
  14. cout << ans << endl;
  15. if(ans >= p){
  16. cout << k << endl;
  17. return 0;
  18. }
  19. }
  20. }
Success #stdin #stdout 0s 5320KB
stdin
7 1.0000
stdout
0
0.214286
0.428571
0.628571
0.8
0.928571
1
6