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

Discussion in 'C' started by neo_sharath, Jan 16, 2009.

1. ### neo_sharathNew Member

Joined:
Jan 16, 2009
Messages:
2
0
Trophy Points:
0
Hello,
I have calculated using this table:-
[FONT=&quot]Input Register[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]Output Register[/FONT]
[FONT=&quot]|0>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]1[/FONT]
[FONT=&quot]|1>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]7[/FONT]
[FONT=&quot]|2>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]4[/FONT]
[FONT=&quot]|3>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]13[/FONT]
[FONT=&quot]|4>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]1[/FONT]
[FONT=&quot]|5>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]7[/FONT]
[FONT=&quot]|6>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]4[/FONT]
[FONT=&quot]|7>[/FONT]
[FONT=&quot]7 Mod 15[/FONT]
[FONT=&quot]13[/FONT]

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......

2. ### neo_sharathNew Member

Joined:
Jan 16, 2009
Messages:
2
0
Trophy Points:
0
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.

3. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
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,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)) ?

Joined:
Aug 6, 2004
Messages:
3,012