long a = s.nextInt();
long m = s.nextInt();
m <= 10^10 and a<m
use s.nextLong() instead
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…
https://www.codechef.com/viewsolution/34708781
The Exact same code that of Editorialist with just change In variables is giving TLE…
What’s wrong here…? Compiler or the code.
Plz someone help me I’m unable to figure it out
TLE Solution : CodeChef: Practical coding for everyone
AC Solution : CodeChef: Practical coding for everyone
The only difference between them is each operator and operand have spaces between them .
Do the spaces between operators and operands really matter that much…??
Help me do not know where my code is failing
Here is my solution
#include<bits/stdc++.h>
using namespace std;
/*
do not voilate rules
*/
void fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}int main()
{
fastio();
long long int t;
cin>>t;
while(t–)
{
long long int a,m,n,d;cin>>a>>m; float tester; if(a!=0) { tester=(float)m/a; } n=(long long int)tester; float diff; set<int>s; while(n>0) { diff=(float)(tester-n); d=diff*a; if(n<d) { break; } if(d!=0&&n%d==0) s.insert(n); n--; } cout<<s.size()<<endl; for(auto it:s) cout<<it<<" "; cout<<endl; }}
plz help me @codinginveins @nagasai74 @rishup_nitdgp
what’s wrong in my code… my output is same as of example output. please help guys.here is my code…
#include
#include
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int a,m,x,count=0;
cin>>a>>m;
x=m/a;
vectorv;
for(int i=x-a;i<=x;i++)
{
int check=m-(a*i);
if(check==0)
continue;
if(i%check==0)
{
v.push_back(i);
count++;
}
}
cout<<count<<’\n’;
for(int i=0;i<v.size();i++)
{
cout<<v[i]<<" ";
}
cout<<’\n’;
}
}
I didn’t understand your logic. Could you explain what is happening in your code?
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int t,a,m,i,flag,b[100003],j,p,q;
scanf("%lld",&t);
for(i=1;i<=t;++i)
{
scanf("%lld%lld",&a,&m);
flag=0;
for(j=1;(j*j)<=m;++j)
{
if((m%j)==0)
{
p=j;
q=m/j;
if(j==1)
{
if((q%a)==1)
{
flag+=1;
b[flag]=(q/a)*p;
}
}
else
{
if(p==q)
{
if((q%a)==1)
{
flag+=1;
b[flag]=(q/a)*p;
}
}
else
{
if((q%a)==1)
{
flag+=1;
b[flag]=(q/a)*p;
}
if((p%a)==1)
{
flag+=1;
b[flag]=(p/a)*q;
}
}
}
}
}
if(flag==0)
{
printf(“0\n”);
}
else
{
sort(b+1,b+flag+1);
printf("%lld\n",flag);
for(j=1;j<=flag;++j)
{
printf("%lld “,b[j]);
}
}
printf(”\n");
}
}
Can anyone tell why is this code getting “WA”? I