using System;using System.Linq;publicclassModSystem{publicstaticstringfromNb2Str(int n,int[] sys){return sys.Aggregate((a,b)=>a*b)<=n || Enumerable.Range(2,sys.Max()-2).Count(x=>sys.Count(y=>y%x==0)>1)>0?"Not applicable":string.Concat(sys.Select(x=>"-"+n%x+"-"));}}
答案2:
using System;using System.Numerics;publicclassModSystem{publicstaticStringfromNb2Str(int num,int[] mArr){string result ="-";BigInteger prod =1;bool fCoprime =true;for(int i=0; i<mArr.Length; i++){
prod *= mArr[i];
result +=(num % mArr[i]+"--");for(int j=i+1; j<mArr.Length; j++){if(Factorize(mArr[i],mArr[j])!=1){
fCoprime =false;
result ="Not applicable";break;}}if(!fCoprime){break;}}
result = prod < num ?"Not applicable": result.Substring(0,result.Length-1);return result;}publicstaticintFactorize(int a,int b){int g = a ==0? b : a;return a ==0|| b ==0? g :Factorize(b, a % b);}}
答案3:
using System;using System.Linq;using System.Collections.Generic;publicclassModSystem{publicstaticStringfromNb2Str(int n,int[] sys){var result ="Not applicable";if(sys.OfType<int>().ToList().Aggregate((a,b)=>a*b)<= n)return result;for(var i =0; i < sys.Length; i++)for(var j = i +1; j < sys.Length; j++)if(GetGCDByModulus(sys[i], sys[j])>1)return result;
result = String.Join("", sys.OfType<int>().ToList().Select(x=>String.Format("-{0}-", n%x)));return result;}publicstaticintGetGCDByModulus(int value1,int value2){while(value1 !=0&& value2 !=0){if(value1 > value2)
value1 %= value2;else
value2 %= value1;}return Math.Max(value1, value2);}}
答案4:
using System;publicclassModSystem{privatestaticboolcoprime(int a,int b){if(b ==0){return a ==1;}else{returncoprime(b, a % b);}}publicstaticStringfromNb2Str(int n,int[] sys){int p =1;foreach(int v in sys){
p *= v;}if(p <= n){return"Not applicable";}for(int i =0; i < sys.Length; i++){for(int j = i+1; j < sys.Length; j++){if(!coprime(sys[i],sys[j])){return"Not applicable";}}}String res ="";for(int i =0; i < sys.Length; i++){
res = res +"-"+ n % sys[i]+"-";}return res;}}
答案5:
using System.Linq;publicclassModSystem{privatestaticreadonlystring NA ="Not applicable";privatestaticintGCF(int x,int y)=>(y ==0)? x :GCF(y, x % y);publicstaticstringfromNb2Str(int n,int[] sys){// Throw out invalid inputif(n <0|| sys ==null|| sys.Length ==0)return NA;if(sys.Aggregate(1,(acc, cur)=> acc * cur)< n)return NA;for(var i =0; i < sys.Length; i++)for(var j = i +1; j < sys.Length; j++)if(GCF(sys[i], sys[j])>1)return NA;returnstring.Concat(sys.Select(num => $"-{n % num}-"));}}
答案6:
using System;using System.Linq;publicclassModSystem{publicstaticStringfromNb2Str(int n,int[] sys){int modRazem =1;for(int i =0; i < sys.Length; i++) modRazem *= sys[i];if(modRazem < n)return"Not applicable";int mini = sys.Min();for(int i = mini; i >1; i--){int check =0;for(int j =0; j < sys.Length; j++){if(sys[j]% i ==0) check++;}if(check >1)return"Not applicable";}int[] rns = sys.Select(x => n % x).ToArray();string res ="-";
res +=string.Join("--", rns.Select(x =>""+ x));return res +"-";}}
答案7:
publicclassModSystem{publicstaticstringfromNb2Str(int n,int[] sys){bool isGreaterN =false;bool isPairwiseCoPrime =false;int temp =1;foreach(int cur in sys){ temp *= cur;}
isGreaterN = temp < n ?false:true;if(!isGreaterN)return"Not applicable";for(int i =0; i < sys.Length; i++)for(int j = i +1; j < sys.Length; j++)if(GCD(sys[i], sys[j])==1) isPairwiseCoPrime =true;elsereturn"Not applicable";if(!isPairwiseCoPrime)return"Not applicable";string res ="-";for(int i =0; i < sys.Length; i++)
res += n % sys[i]+"--";return res.Remove(res.Length -1);}publicstaticintGCD(int leftNum,int rightNum){while(rightNum !=0){int tmp = leftNum % rightNum;
leftNum = rightNum;
rightNum = tmp;}return leftNum;}}
答案8:
using System;using System.Linq;publicclassModSystem{publicstaticStringfromNb2Str(int n,int[] sys){if(!IsValidSystem(n, sys))return"Not applicable";int[] modulos =newint[sys.Length];for(int x =0; x < sys.Length; x++)
modulos[x]= n % sys[x];returnstring.Join("", modulos.Select(i => $"-{i}-"));}publicstaticboolIsValidSystem(int n,int[] sys){var product = sys.Aggregate((x, y)=> x * y);if(n >= product)returnfalse;for(int indexx =0; indexx < sys.Length; indexx++)for(int indexy = indexx +1; indexy < sys.Length; indexy++)if(GCD(sys[indexx], sys[indexy])!=1)returnfalse;returntrue;}publicstaticintGCD(int a,int b){while(a !=0&& b !=0){if(a > b){
a %= b;}else{
b %= a;}}return a ==0? b : a;}}
答案9:
using System;using System.Collections.Generic;using System.Linq;using System.Text;publicclassModSystem{publicstaticStringfromNb2Str(int n,int[] sys){StringBuilder sb =newStringBuilder();if(!IsPairwiseCoprimeSystem(sys)||Product(sys)<= n){return"Not applicable";}else{var strParts = sys.Select(m => $"-{n%m}-");foreach(string part in strParts){
sb.Append(part);}}return sb.ToString();}publicstaticboolIsPairwiseCoprimeSystem(int[] sys){
HashSet<int> moduliCheckedForCoprime =newHashSet<int>();foreach(int currentModuli in sys){
moduliCheckedForCoprime.Add(currentModuli);var otherModuli = sys.Where(m =>!moduliCheckedForCoprime.Contains(m));if(otherModuli.Select(m =>AreCoprimes(currentModuli,m)).Where(cp =>!cp).Any()){returnfalse;}}returntrue;}publicstaticboolAreCoprimes(int num1,int num2){int largest = num1 > num2 ? num1 : num2;for(int i =2; i <=(largest/2)+1; i++){if((num1 % i)==0&&(num2 % i)==0){returnfalse;}}returntrue;}publicstaticintProduct(int[] sys){return sys.Aggregate((a,b)=> a*b);}}
答案10:
using System;using System.Collections.Generic;using System.Linq;publicclassModSystem{publicstaticStringfromNb2Str(int n,int[] sys){string output ="";int check1 = sys[0];for(int i =1;i<sys.Length;i++){
check1 *= sys[i];}if(n >= check1){return"Not applicable";}
List<int> CoPrime =newList<int>();foreach(int i in sys){for(int j =2; j <= i; j++){if(i % j ==0){
CoPrime.Add(j);}}}int check2 = CoPrime.Count;
CoPrime = CoPrime.Distinct().ToList();int check3 = CoPrime.Count;if(check2!=check3){return"Not applicable";}foreach(int i in sys){
output +="-"+ n%i +"-";}return output;}}