fork download
  1. //package Q07;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7. /**
  8.  * Created by Shreyans Sheth [bholagabbar] on 10/15/2015 at 4:32 PM using IntelliJ IDEA (Fast IO Template)
  9.  */
  10.  
  11. class solve
  12. {
  13.  
  14. static boolean[] p=new boolean[55];
  15. static double[][] C=new double[20][20];
  16.  
  17. static void Sieve()
  18. {
  19. Arrays.fill(p, true);
  20. p[0]=p[1]=false;
  21. for(int i=2;i<=Math.sqrt(50);i++)
  22. if(p[i])
  23. for(int j=i*i;j<=50;j+=i)
  24. p[j]=false;
  25. }
  26.  
  27. static void COMB()
  28. {
  29. for(int i=0;i<=18;i++)
  30. for(int j=0;j<=i;j++)
  31. {
  32. if(j==0||j==i)
  33. C[i][j]=1;
  34. else
  35. C[i][j]=C[i-1][j-1]+C[i-1][j];
  36. }
  37. }
  38.  
  39. public static void main(String[] args) throws Exception
  40. {
  41. //System.setIn(new FileInputStream("E:\\Shreyans\\Documents\\QBIT_2015\\src\\Q07\\input.txt"));
  42. Scanner sc=new Scanner(System.in);
  43. DecimalFormat df=new DecimalFormat("0.0000");
  44. Sieve();
  45. COMB();
  46. int t=sc.nextInt();
  47. while(t-->0)
  48. {
  49. double a=0;
  50. double b=0;
  51. int SkillOfTeamA=sc.nextInt(),SkillOfTeamB=sc.nextInt();
  52. double Sa=SkillOfTeamA/100.0;
  53. double Sb=SkillOfTeamB/100.0;
  54. for(int i=2;i<=18;i++)
  55. if(p[i])
  56. {
  57. a+=Math.pow(Sa,i)*Math.pow(1.0-Sa,18-i)*C[18][i];
  58. b+=Math.pow(Sb,i)*Math.pow(1.0-Sb,18-i)*C[18][i];
  59. //System.out.println(a+" "+b+" "+Math.pow(Sa,i)+" "+Math.pow(1.0-Sa,18-i)+" "+C[18][i]);
  60. }
  61. double ans=1.0-((1.0-a)*(1.0-b));
  62. System.out.println(df.format(ans));
  63. }
  64. }
  65. }
Success #stdin #stdout 0.16s 321344KB
stdin
1
78 12
stdout
0.6677