比赛 防止浮躁的小练习v0.6 评测结果 AAAAAAAAAA
题目名称 同余方程 最终得分 100
用户昵称 kito 运行时间 0.023 s
代码语言 C++ 内存使用 0.26 MiB
提交时间 2016-10-20 16:33:31
显示代码纯文本
  1. #include<cstdio>
  2. using namespace std;
  3. #define fcl fclose(stdin); fclose(stdout); return 0
  4. #define SUBMIT 2333
  5. typedef long long LL;
  6. LL A,B;
  7. void ExGcd(LL a,LL b,LL& x,LL& y){
  8. if(b==0){
  9. x=1; y=0;
  10. return;
  11. }
  12. ExGcd(b,a%b,x,y);
  13. LL t=x;
  14. x=y; y=t-(a/b)*y;
  15. }
  16.  
  17. int main(){
  18. #ifdef SUBMIT
  19. freopen("mod.in","r",stdin);
  20. freopen("mod.out","w",stdout);
  21. #endif
  22. scanf("%lld%lld",&A,&B);
  23. LL x,y;
  24. ExGcd(A,B,x,y);
  25. x%=B;
  26. x=(x+B)%B;
  27. printf("%lld",x);
  28. #ifndef SUBMIT
  29. getchar(); getchar();
  30. #endif
  31. fcl;
  32. }