Ejemplo n.º 1
0
 public void Givenexample_GfuncShouldReturn10()
 {
     var twoFour = new TotientPair(1);
     twoFour.Number = 4;
     twoFour.Totient = 2;
     var fourSix = new TotientPair(1);
     fourSix.Number = 6;
     fourSix.Totient = 4;
     long result = GFunc(twoFour, fourSix);
     Assert.Equal(10, result);
 }
Ejemplo n.º 2
0
        public static long GFunc(TotientPair n, TotientPair m)
        {
            long dmNdivisor = m.Number;
            long dmN = m.Number % n.Number;
            long ntmt = n.Totient - m.Totient;

            while (ntmt < 0)
            {
                ntmt = ntmt + n.Number;
            }
            ntmt = ntmt % n.Number;
            if (dmN != 1)
            {
                if (m.Number % dmN != 0) { return 0; }
                dmNdivisor = m.Number / dmN;
            }
            return (m.Totient + dmNdivisor * ntmt) % (dmNdivisor * n.Number);
        }