zoukankan      html  css  js  c++  java
  • 【ECJTU_ACM 11级队员2012年暑假训练赛(8) B Modular Inverse】

    B题要套一个数论的模版,注意m=1!! C题可以二分匹配,把行列看作点; 不能开百度,开谷歌搜题解,再次强调!一经发现,取消成绩!

    ECJTU_ACM 11级队员2012年暑假训练赛(8)
    4:30:00
     
     
              
    B - Modular Inverse
    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

    Description

    The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1x (mod m). This is equivalent toax≡1 (mod m).

    Input

    There are multiple test cases. The first line of input is an integer T ≈ 2000 indicating the number of test cases.

    Each test case contains two integers 0 < a ≤ 1000 and 0 < m ≤ 1000.

    Output

    For each test case, output the smallest positive x. If such x doesn't exist, output "Not Exist".

    Sample Input

    3
    3 11
    4 12
    5 13
    

    Sample Output


    FAQ | About Virtual Judge | Forum | Discuss | Open Source Project
    All Copyright Reserved ©2010-2012 HUST ACM/ICPC TEAM 
    Anything about the OJ, please ask in the forum, or contact author:Isun
    Server Time: 
     
     
     
      1 // Project name : B ( Modular Inverse ) 
      2 // File name    : main.cpp
      3 // Author       : iCoding
      4 // E-mail       : honi.linux@gmail.com
      5 // Date & Time  : Fri Aug 10 13:23:03 2012
      6 
      7 
      8 #include <iostream>
      9 #include <stdio.h>
     10 #include <string>
     11 #include <cmath>
     12 #include <algorithm>
     13 using namespace std;
     14 
     15 /*************************************************************************************/
     16 /* data */
     17 
     18 #ifndef MAXN
     19 #define MAXN 2000
     20 #endif
     21 
     22 /*************************************************************************************/
     23 /* procedure */
     24 
     25 bool iCanGo[MAXN];
     26 
     27 void iInit()
     28 {
     29     /*init iCanGo*/
     30     for (int i = 0; i < MAXN; i++)
     31     {
     32         iCanGo[i] = true;
     33     }
     34 }
     35 
     36 void iJudge(int a, int n)
     37 {
     38     /*give me a TLE????? Come on,,,go on!!!!!!*/
     39     iInit();
     40     bool iEnd   = false;
     41     bool iFound = false;
     42     int iIndex  = 0;
     43     while (!iEnd)
     44     {
     45         if ((n * iIndex + 1) % a == 0)
     46         {
     47             cout << (n * iIndex + 1) / a << endl;
     48             iEnd   = true;
     49             iFound = true;
     50         }
     51         else
     52         {
     53             if (iCanGo[(n * iIndex + 1) % a] == false)
     54             {
     55                 iEnd = true;
     56             }
     57            // iCanGo[(n * iIndex + 1) % a] = false;
     58             cout << (n *iIndex + 1) % a << endl;
     59         }
     60         iIndex++;
     61     }
     62     if (iFound == false)
     63     {
     64         cout << "Not Exist" << endl;
     65     }
     66 
     67     /******************************************************************************************/
     68     /******************************************************************************************/
     69     /******************************************************************************************/
     70     /******************************NO!NO!NO!NO!NO!NO!NO!NO!NO!NO!NO!***************************/
     71     /******************************************************************************************/
     72     /******************************************************************************************/
     73     /******************************************************************************************/
     74     /******************************************************************************************/
     75     /******************************************************************************************/
     76     /******************************************************************************************/
     77     /******************************************************************************************/
     78     /**************************                                              ******************/
     79     /*************************************************  ***************************************/
     80     /*************************************************  ***************************************/
     81     /*************************************************  *************************             */
     82     /*************************************************  ***************************************/
     83     /*************************************************  ***************************************/
     84     /*************************************************  ************ **************************/
     85     /*************************************************  ***************************************/
     86     /*************************************************  ***************************************/
     87     /********************************************** **** **********     ***********************/
     88     /*************************************************************        *********************/
     89     /**************                                            ********************************/
     90     /********************************************** *******************************************/
     91     /*********************************************** ******************************************/
     92     /******************************************************                               *****/
     93     /************************************************  *                         **************/
     94     /******************************************************************************************/
     95     /******************************************************************************************/
     96     /******************************************************************************************/
     97     /******************************************************************************************/
     98     /****************************                   *******************************************/
     99     /******************************************************************************************/
    100     /******************************************************************************************/
    101     /******************************************************************************************/
    102     /******************************************************************************************/
    103     /******************************************************************************************/
    104     /******************************************************************************************/
    105     /******************************************************************************************/
    106     /******************************************************************************************/
    107     }
    108 
    109 /*************************************************************************************/
    110 /* main */
    111 int main()
    112 {
    113     int iT;
    114     cin >> iT;
    115     while (iT--)
    116     {
    117         int a, n;
    118         cin >> a >> n;
    119         iJudge(a, n);
    120     }
    121     return 0;
    122 }
    123 // end 
    124 // Code by Sublime text 2
    125 // iCoding@CodeLab 
  • 相关阅读:
    PDO事务处理不能保持一致性
    Android开发中的SQLite事务处理
    Mysql安装
    IIS下https配置及安全整改
    exchang2010OWA主界面添加修改密码选项
    查阅文件技巧
    RHEL yum
    CentOS之——CentOS7安装iptables防火墙
    Linux修改主机名称
    Vmware虚拟机设置静态IP地址
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2635963.html
Copyright © 2011-2022 走看看