What is this statement for?
https://www.codechef.com/viewsolution/28592030
Can any one help me understand why I am getting RE (NZEC) for this solution?
even with this its not passing original constraints !!?.. what to do !?
PS: i used the same approach and code is almost similar too as that of editorialist
The “almost” similar code has a bug then.
Sorry, I don’t know JAVA that well, I code in C++
long a = s.nextInt();
long m = s.nextInt();
m <= 10^10 and a<m
use s.nextLong() instead
Use long for storing A and M
We are storing all the factors of M in set div. If j is a factor of M that means M/j is a factor too. Hence, inserting both j and M/j in div.
for (long f : arrLL){
if ((f-1)%a == 0){
long q = (f-1)/(int)a;
**long d = (int)m/f;**
long n = q*d;
if (n != 0 ){
newarrLL.add(n);
count ++;
}
}
}
@raksha1906
It is a similar mistake, typecasting long m to int will alter the value of m for values lying outside the range of integer which will result in unexpected output.
You may replace
long d = (int)m/f;
with
long d = m/f;
it got solved … thanks
while (t–>0) {
long a = s.nextLong();
long m = s.nextLong();
ArrayList<Long>mr= new ArrayList<>();
long k =(long) Math.floor(Math.sqrt(m));
for (int j = 1; j <=k; j++) {
if (m%j==0){
long r = m/j;
if ((j-1)%a==0){
mr.add(((j-1)/a)*r);
}
if( r!=j){ // THIS BLOCK
if ((r-1)%a==0){
mr.add(((r-1)/a)*j);
}
}
}
}
System.out.println(mr);
}
hey can you also explain me what the second if block is doing ?
this is for …
since q = (j-1)/a … and q is an integer, so j-1 should be completely divisible a…
so (j-1)%a == 0 helpes in checking whether this condition is satisfied or not … and only accepts those values of q which satisfies the condition
yes that’s the first if block what about this one ?? i wasn’t able to come up with this condition
My solution is little bit different .it is able to pass 50 % but next its showing TLE. can anyone please help CodeChef: Practical coding for everyone
Here j is a factor of M as it satisfies (M%j==0) and we store a corresponding value of N in mr [Explained in editorial]
Coming to the second block, we have r = M/j where j is a factor of M which means r is a factor too eg. 5 is a factor of 10 and 10/5 = 2 is a factor of 10. So we have to add the corresponding value of N in mr for r but if r is same as j we will get repeating values of N so we put condition if(r!=j)
Your approach is taking O(N) time.
Hi I just used use the approach:
for i = a%m to i<=m and incrementing i = i + a:
so now if((m-a)/a)%i == 0 && i != 0)
we can insert into some vector…
But this approach is giving me WA
Ik it should give some TLE but why WA?
I used the same approach given here , But even though getting TLE for Subtask 2
https://www.codechef.com/viewsolution/34707506
Can anyone say me where I’m missing out…
