fork download
  1. #include <stdio.h>
  2.  
  3. #define m 100000000003LL
  4.  
  5. long long int x,y,val;
  6.  
  7. void extendedEuclid(long long int a,long long int b)
  8. {
  9. if (b==0)
  10. {
  11. val=b;
  12. x=1;y=0;
  13. }
  14. else
  15. {
  16. extendedEuclid(b,a%b);
  17. long long int temp=x;
  18. x=y;
  19. y=temp-(a/b)*y;
  20. }
  21. }
  22.  
  23. long long int modInverse(long long int a,long long int b)
  24. {
  25. extendedEuclid(a,b);
  26. return (x%b+b)%b;
  27. }
  28.  
  29. long long int cipher[6];
  30.  
  31. int main()
  32. {
  33. int testCases;
  34. scanf("%d",&testCases);
  35. while (testCases--)
  36. {
  37. int hash=0;
  38. long long int a,b,key;
  39. for (int i=0;i<6;i++)
  40. {
  41. scanf("%lld",&cipher[i]);
  42. if (cipher[i+1]==cipher[i])
  43. hash++;
  44. }
  45. if(hash)
  46. printf("%lld\n",cipher[0]%m);
  47. else
  48. {
  49. a=((cipher[2]-cipher[1])%m*modInverse(cipher[1]-cipher[0],m))%m;
  50. key=(((a%m+1%m)%m*cipher[5]%m)%m-(a%m*cipher[4]%m)%m)%m;
  51. printf("%lld\n",key%m);
  52. }
  53. }
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 9432KB
stdin
1
0 0 0 0 0
stdout
0