fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. constexpr float a(float y) { return y/29; }
  8. constexpr float b(float y) { return 29*y; }
  9. constexpr int T(float x) {
  10. for (int z=255;z>=0;z--)
  11. for (int y=255;y>=0;y--)
  12. if (x==a(b(x/z)*y))
  13. return y;
  14.  
  15. return 0;
  16. }
  17. int main() {
  18. float Si[10] = { 30,10,20,15,35,47,18,3,5};
  19. float Ws=1; int x;
  20. for (int i=1;i<=9;i++) {
  21. Ws=a(Si[i-1]*Ws);
  22. printf("%f == %f \n", Si[i-1],Ws);
  23. }
  24. printf("\n");
  25. for (int i=9;i>=1;i--) {
  26. x=T(Ws);
  27. Ws=b(Ws/x);
  28. printf("%d %f \n",x, Ws);
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
30.000000 == 1.034483 
10.000000 == 0.356718 
20.000000 == 0.246013 
15.000000 == 0.127248 
35.000000 == 0.153575 
47.000000 == 0.248897 
18.000000 == 0.154488 
3.000000 == 0.015982 
5.000000 == 0.002755 

255 0.000313 
255 0.000036 
255 0.000004 
254 0.000000 
255 0.000000 
255 0.000000 
255 0.000000 
255 0.000000 
255 0.000000