using System;using System.Collections.Generic;using System.Linq;publicstaticclassKprimesSteps{privatestaticlongKOf(long n){long k =0, m = n;while(m %2==0){
m /=2;
k++;}for(long i =3; i <= Math.Sqrt(n); i +=2)while(m % i ==0){
m /= i;
k++;}if(m !=1)
k++;return k;}publicstatic List<long[]>KprimesStep(int k,int step,long start,long stop){
List<long[]> result =newList<long[]>();for(long i = start; i <= stop - step; i++)if(KOf(i)== k &&KOf(i + step)== k)
result.Add(newlong[]{i, i + step});return result;}}
答案2:
using System;using System.Collections.Generic;using System.Linq;publicclassKprimesSteps{privatestaticintcountPrimeDiv(long n){int cnt =0;for(long i =2; i * i <= n; i++){while(n % i ==0){
cnt++;
n /= i;}}if(n >1) cnt++;return cnt;}publicstatic List<long[]>KprimesStep(int k,int step,long start,long nd){
List<long[]> res =newList<long[]>();long i = start;while(i <= nd-step){if((countPrimeDiv(i)== k &&countPrimeDiv(i+step)== k))
res.Add(newlong[]{i, i+step});
i++;}return res;}}
答案3:
using System;using System.Collections.Generic;publicclassKprimesSteps{publicstatic List<long[]>KprimesStep(int k,int step,long start,long nd){
List<long[]> res =newList<long[]>();for(long j = start; j <= nd - step; j++){if(IsKPrime(j, k)&&IsKPrime(j + step, k)){
res.Add(newlong[]{ j, j + step });}}return res;}privatestaticboolIsKPrime(long number,int k){int numPrimes =0;while(number %2==0){
number /=2;
numPrimes++;}for(int i =3; i * i <= number; i +=2){while(number % i ==0){
number /= i;
numPrimes++;}}if(number !=1){
numPrimes++;}return numPrimes == k;}}
答案4:
using System.Collections.Generic;publicclassKprimesSteps{publicstatic List<long[]>KprimesStep(int k,int step,long start,long nd ){var result =newList<long[]>();for(long n = start; n <= nd - step; n++){if(GetFactorsCount( n )== k &&GetFactorsCount( n + step )== k ){
result.Add(new[]{n, n + step});}}return result;}privatestaticintGetFactorsCount(long n ){var result =0;long factor =2;while( factor*factor <= n ){while( n%factor ==0){
result +=1;
n /= factor;}
factor +=1;}if( n >1){
result +=1;}return result;}}
答案5:
using System;using System.Collections.Generic;using System.Linq;publicclassKprimesSteps{publicstatic List<long[]>KprimesStep(int k,int step,long start,long nd){
List<long[]> res =newList<long[]>();long n = start;long end = nd;while(n <= nd - step){long[] temp =pierwsze(n);int check =0;if(temp.Length >0) check =ileCzynnik(temp, n);if(check == k){long bis = n + step;long[] tempBis =pierwsze(bis);int checkBis =0;if(tempBis.Count()>0) checkBis =ileCzynnik(tempBis, bis);if(checkBis == k) res.Add(newlong[]{ n, bis });}
n++;}return res;}publicstaticlong[]pierwsze(long a){long temp =(long)Math.Sqrt(a);
List<long> lista =newList<long>();while(temp >1){if(a % temp ==0){int temp2 =(int)Math.Sqrt(temp);int check =0;while(temp2 >1){if(temp % temp2 ==0){
check =1;
temp2 =1;}
temp2--;}if(check ==0) lista.Add(temp);long temp2Bis = a / temp;if(temp2Bis != temp){int temp2BisSqr =(int)Math.Sqrt(temp2Bis);
check =0;while(temp2BisSqr >1){if(temp2Bis % temp2BisSqr ==0){
check =1;
temp2BisSqr =1;}
temp2BisSqr--;}if(check ==0) lista.Add(temp2Bis);}}
temp--;}return lista.ToArray();}privatestaticintileCzynnik(long[] a,long n){
a = a.OrderByDescending(x => x).ToArray();int i =0;int res =0;while(n !=1){while(n % a[i]==0){
n /= a[i];
res++;}
i++;}return res;}}
答案6:
using System;using System.Collections.Generic;using System.Linq;publicclassKprimesSteps{publicstatic List<long[]>KprimesStep(int k,int step,long start,long nd){
List<long[]> res =newList<long[]>();for(long i = start; i <= nd - step; i++){if(FindK(i, k)&&FindK(i + step, k)){
res.Add(newlong[]{i, i + step});}}return res;}privatestaticboolFindK(long n,int k){var count =0;for(var i =2; i * i <= n; i++){while(n % i ==0){
count++;if(count > k){returnfalse;}
n /= i;}}if(n >1){
count++;}return count == k;}}
k-primes中的步骤【难度:2级】:答案1:using System;using System.Collections.Generic;using System.Linq;public static class KprimesSteps { private static long KOf(long n) { long k = 0, m = n; while...