In the first part, 9801 numbers with duplicates will be saved in a txt file.In the middle, I wished to count the number of "not duplicated" terms(here is the problem because this answer is correct for small amount of terms but for 9801 terms)
#include <stdio.h>
int Next;Next=0;
int fp(int);
int main()
{
FILE *nums;
nums=fopen("C:\\Users\\Malith\\Desktop\\nums.txt","w");
char n[250];int a,b,k,places,i,counter;
counter=0;
for(i=0;i<250;i++){n[i]=0;}
for( a=2;a<=100;a++)
{
n[0]=a;
places=1;
for(b=2;b<=100;b++)
{
k=0;
while(Next>0||k<places)>
{
n[k]=fp(n[k]*a+Next);
k++;
}
for(i=k-1;i>=0;i--)
{
fprintf(nums,"%d",n[i]);
}
fprintf(nums," ");counter++;
places=k;
}
for(i=0;i<k;i++){n[i]> }
printf("The number of total terms is %d\n",counter);
fclose(nums);
/* Now I've stored all 9801(counter) generated numbers in a txt file on my dextop,
next part is about filtering the duplicates*/
FILE *RMain,*RSub;
RMain=fopen("C:\\Users\\Malith\\Desktop\\nums.txt","r");
int p,q,cnt,In,count,ct;
count=0;ct=0;
char dp[800][250],tM[250],tS[250];
for(p=0;p<counter;p++)>
{
fscanf(RMain,"%s",tM);
cnt=0;In=1;
RSub=fopen("C:\\Users\\Malith\\Desktop\\nums.txt","r");
for(q=0;q<counter;q++)>
{
fscanf(RSub,"%s",tS);
if(strcmp(tM,tS)==0){cnt++;}
/*for numbers without duplicates, cnt will be 1,
and for duplicates it'll be more than 1*/
if(cnt>1){In=0;strcpy(dp[ct],tM);ct++;break;}
/*store the duplicates in dp[] array.For a example,
if there were two 16s in the txt file,
the dp[] array will have two 16s.*/
}
if(In==1){count++;}
/* "In" remains as 1 <=>(cnt=1) if "p" hasn't a duplicate*/
}
printf("count is %d ct is %d \n",count,ct);
/*count:-number of distinct numbers without all duplicates,
ct:-number of all duplicates(ex:-16,17,18,16,16,17 >> count=1, ct=5)*/
int min,A,B; min=0;
/*min:-ex>> for any number of duplicates by "16" in the dp[] array,
min will be increased in only 1 */
for(A=0;A<ct-1;a++)>
{
if(strcmp(dp[A],"")==0){continue;}
for(B=A+1;B<ct;b++)>
{
if(strcmp(dp[A],dp[B])==0){strcpy(dp[B],"");}
}
min++;
}
printf("Final Answer is %d",count+min);
}
int fp(int g)
{
int backup_g;
backup_g=g;
while(g>=10) { g-=10;}
Next=(backup_g-g)/10;
return g;
}