Tuesday, May 15, 2012
SRM 150 DIV1 - 250
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;
public class InterestingDigits
{
private int newsum(int n,int b)
{
int s=0;
while(n!=0)
{
s+=n%b;
n=n/b;
}
return s;
}
public int[] digits(int base)
{
int m=1;
int r[]=new int[base];
int ri=0;
for(int i=0;i<4;i++)
m*=base;
for(int p=2;p<base;p++)
{
boolean pass=true;
for(int i=0;i<m;i+=p)
{
if((newsum(i,base)%p)!=0)pass=false;
}
if(pass)r[ri++]=p;
}
int r2[]=new int[ri];
for(int i=0;i<ri;i++)
r2[i]=r[i];
return r2;
}
}
Labels:
150,
competitive,
DIV,
java,
programming,
srm
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment