#include #include #include #define ROWS 15 /*number of displaying rows, you can change it as you want*/ /* We restrict arguments of T(a,b) by those integers, that have only first 100,000 prime numbers in factorization into prime numbers. 1299709 is the 100,000-th prime number. */ #define maxBits 1299708 int primes[100000]; unsigned char bits[maxBits]; int isPrimesInitialized = 0; int getA325028(int i); int findOpt(int a, int b); int engine(int a, int b, int c); void initPrimes(); int gcd(int a, int b); int primeDivisors(int a, int *mas1, int *mas2); int my_round(int a, int b, int down); int main() { int i,j; j=1; for(i=1;i<=(ROWS+1)*ROWS/2;i++) { if (i==(j*(j+1)/2)) { printf("%d\n",getA325028(i)); j++; } else printf("%d ",getA325028(i)); } return 0; } int getA325028(int i) { int a,b; if (i<=0) { printf("Illegal index. Index should be positive integer\n"); return -1; } if (isPrimesInitialized==0) { initPrimes(); /*initialization of prime numbers table*/ isPrimesInitialized=1; } /* triangle bijection of the positive integer to an ordered pair */ b=ceil((sqrt(1+8.0*i)-1)/2); a=i-1-b*(b-1)/2; return(findOpt(a,b)); } /*calculation of T(a,b) using all properties*/ int findOpt(int a, int b) { int lowerBound, upperBound, value, i, k, gcd_val, result; float i_float; if (a>=b) return(0); if (a==1) { if (b==2) return(1); if (b==3) return(2); if (b==4) return(2); else return(2); } if (a==0) return(1); gcd_val=gcd(a,b); if (b-a < a+1) { lowerBound = gcd_val; upperBound=2*(b-a)-1; } else { if (b>a*a+a) return(a+1); lowerBound = floor(((float)(b-a))/(a+1)); if (gcd_val>lowerBound) lowerBound=gcd_val; upperBound=b; } value=1000000; for (i=lowerBound;i<=upperBound;i++) { k=engine(a,b,i); if (k (k4-a)) return(k2); else if (down==1) return(k1); else return(k2); } /* rhd(x) = floor(ceil(2*x)/2); rhu(x) = ceil(floor(2*x)/2); T(n, k) = {v = vector(n, z, rhd(n/z) - rhu(k/z) + abs(z*rhu(k/z)-k) + abs(z*rhd(n/z)-n)); (vecsort(v, , 1))[1]; } tabl(13) = for (n=1, 13, for (k=0, n-1, print1(T(n, k), ", ")); print); */