### Solving with modulus

what number can be divided by 7 without a remainder but when divided by 2 3 4 5 or 6 leaves 1?

I've found the riddle answer for the above question to be 301
but I can't figure out how to write a c++ program to find me the answer using %. Some hints on how to go about this would be highly appreciated,

Thank You.
How did you figure it out without a program? Just translate that thought pattern into something a computer understands
Last edited on
Try Something like this:
 ``1234567891011121314`` ``````#include iostream int main(){ int NumberEntered = 0; while(NumberEntered % 7 != 0 && NumberEntered % 2 != 1 && NumberEntered % 3 != 1 && NumberEntered % 4 != 1 && NumberEntered % 5 != 1 && NumberEntered % 6 != 1) NumberEntered++; //You could also do && NumberEntered != 301 if you do not want 301 as an answer std::cout >> NumberEntered; return 0; }``````

Check if the number is valid, if not start again with the next number.
Last edited on
I basically did LCM of 2,3,4,5,6 which is 60...

then I added 1 to make it 61 and tested it using % and it wasn't funny divisible by 7.

so I kept adding the LCM 61 121 181 241 301

the first one that left no remainder was 301.

I tried something similar to your code Pickle but it seems very tedious because I need to go through every single number until I get to 301.

this is what I currently have:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````void main() { int a[7],n,i,j,c,max,min; unsigned long prod; printf("Enter the no. of entries: "); scanf("%d",&n); printf("Enter the entries:"); for(i=0;i0) a[i]=c; else { printf("Invalid Entry"); return; } } max=a[0]; for(i=0;i=max) max=a[i]; min=a[0]; for(i=0;i

I got up to the LCM but I need a test for % and a for loop to add 60 but I haven't been able to find a way to test the equality.

Hope all of that makes sense... I'm pretty new to c++.
Last edited on
Pretty simple man!

I am writing only the required code you can Add the user part and main() later on!

int flag;
for(int i=1;i<1000;i++)
{

flag=1;

if(i%7==0)
{

for(int j=2;j<7;j++)
if(i%j!=1)
{
flag=0;
break;
}

if(flag==1)
cout<<"match found:"<<i;
continue;

}
}
and its kinda amazing that you figured it out without writing a program! how did you do it?
Apparently by hurting my head on paper ;-; . I guess I needed some sleep because I was heading to the right solution lol...

I'm usually good at programming from PSEUDOCODES but my professor apparently loves giving riddles :'( to dumbfound me haha

Thank you IcyFlame and others the cplusplus community is very helpful and very fast in responding :)

Last edited on
Thanks a lot! Omesh!
Well, do tell me what is pseudo code?
Well its a description or information in a certain manner to help you make a program.

Kind of like a basic algorithm to get you started on how to start and finish the program.

This riddle took me a while because I wasn't sure how to start it.