It is an exercise(P62 Problem 18) in his The Art of Computer Programming. Vol 1:Foundamental Algorithms.
Definition:If $a^p|m$,but $a^{p+1}\nmid m$,We denote $a^p||m$.
Prove or disprove:
If $2^p||n$,Let S be the numerator of $\sum_{i=1}^n \frac{1}{2i-1}$,then $2^{2p}||S$.
Example:
$n=4$ Then $p=2,S=176,2^{2p}=16,16||176$.
My efforts(Have not solved yet).
1.Note that $\sum_{i=1}^n {(2i-1)}=n^2$.(Fail to go on)
2.Programme in C and here is my code.(Compiled in Dev-CPP),no counterexamples are found.
#include
#include
#include
#include
#include
int getpower(int number,int base,int *num);
int getrem(int h,int n,int num);
int main(int argc, char *argv[]) {
int base,n;//In this case,base is 2.
int h=1;
int m=0;
int num;
int cnt=1;
char ch;
FILE *open=fopen("D:\\output.txt","w");//output it into file
printf("Input 'ESC' to quit,press other keys go on.\n");
while(1)
{
if(kbhit())
{
ch=getch();
if(ch == 27)//ESC ASCII
{
printf("Quit.\n");
break;
}
fprintf(open,"%d Data output.\n",cnt++);
printf("Please input base,n:\n");
scanf("%d %d",&base,&n);
getchar();
fprintf(open,"base=%d,n=%d\n",base,n);
getpower(n,base,&num);
num*=num;//change 2^p to 2^2p.
/*
Input base=2 n=48
Output m=4 num=16
*/
for(h=1;h<=n;h++)
{
m+=getrem(h,n,num);
printf("m=%d\n",m);
m%=num;
}
if(m == 0)
{
fprintf(open,"Success.\n");
printf("Success.\n");
}
else
{
fprintf(open,"Fail.\n");
printf("Fail.\n");
}
printf("Input 'ESC' to quit,press other keys go on.\n");
}//kbhit
}
fclose(open);
return 0;
}
int getpower(int number,int base,int *num)
{
//We write number in the form number=(base^p)*a,base does not divide a.The function returns p.
int h=number;
int rem=number%base;
int cnt=0;
while(!rem)
{
number/=base;
cnt++;
rem=number%base;
}
*num=h/number;
return cnt;
}
int getrem(int h,int n,int num)
{
//we multiply mul=1*3*5*...*(2h-3)*(2h+1)...*(2n-1) and calculate the remainder:mul%(base^power).
int cnt;
int mul=1;
for(cnt=1;cnt<=n;cnt++)
{
if(cnt == h)
continue;//We do not need to multiply h;
else
{
mul*=(2*cnt-1);
if(mul>=num)
mul%=num;
}
}
return mul;
}