how to find the PERIOD in the given set of numbers???

Newbie Member
16Jan2009,13:15   #1
neo_sharath's Avatar
Hello,
I have calculated using this table:-
Input Register
7 Mod 15
Output Register
|0>
7 Mod 15
1
|1>
7 Mod 15
7
|2>
7 Mod 15
4
|3>
7 Mod 15
13
|4>
7 Mod 15
1
|5>
7 Mod 15
7
|6>
7 Mod 15
4
|7>
7 Mod 15
13


Code:
#include<stdio.h>
#include<math.h>

mod_func(long int n1,long int n2)
    {
    long int i,w,m;
    for(i=0;i<15;i++)
        {
        w=pow(n1,i);
        m=w%n2;
        printf("m=%ld\n",m);
        }
    }



main()
{
long int n1,n2,limit;
clrscr();
printf("enter n1:");
scanf("%ld",&n1);
printf("enter n2:");
scanf("%ld",&n2);
mod_func(n1,n2);
getch();
}
Now I want to calculate the PERIOD.In the above output we find the pattern "1,7,4,13" to repeat itself.Hence it is the PERIOD.Can you please write the code for how to match this pattern...it should be generic so that it will respont for any given numbers.....can u please help me out......
Newbie Member
16Jan2009,13:20   #2
neo_sharath's Avatar
The table cant be seen properly.
so I am typing it as follows..

the TABLE IS :-
(7 power a) Mod 15 m
(7 power 0) Mod 15 - 1
(7 power 1) Mod 15 - 7
(7 power 2) Mod 15 - 4
(7 power 3) Mod 15 - 13
(7 power 4) Mod 15 - 1
(7 power 5) Mod 15 - 7
(7 power 6) Mod 15 - 4
(7 power 7) Mod 15 - 13

Now,I hope u can understand what I mean.
Mentor
16Jan2009,13:58   #3
xpi0t0s's Avatar
Not going to write it for you. How would you do it on paper? Take one new number at a time, for example:
can you see a period in 1?
What about in 1,7?
What about in 1,7,4?
What about in 1,7,4,13?
What about in 1,7,4,13,1? If yes, how do you know? Can you think of a way to write a test that a computer can work out? Is there any storage you might need?
Do you have to find a complete period twice to determine that there is a repeating pattern? For example 1,7,4,13,1,9,3,6 has a period > 4, but does the maths behind the calculation indicate that 1 must always be followed by 7, which must always be followed by 4 etc? What is (7^n) / (7^(n-1)) ?
Mentor
16Jan2009,13:59   #4
xpi0t0s's Avatar
And what should the program do if someone cruelly tosses in a digits-of-pi generator and asks it to find the period?