예제 #1
0
 public static ModNum Pow(ModNum val, ulong count)
 {
     return(count == 0 ? new ModNum(1) :
            count == 1 ? val :
            count == 2 ? val * val :
            count % 2 == 0 ?
            Pow(Pow(val, count / 2), 2) :
            Pow(Pow(val, count / 2), 2) * val);
 }
예제 #2
0
 private static ModNum Inverse(ModNum val)
 {
     return(Pow(val, mod - 2));
 }