+ 123

*DAILY CHALLENGE* : Given a positive number Write a code that calculates all 'quark-pairs' from 1 .. n!

NEW CHALLENGE HERE: https://www.sololearn.com/discuss/626739/?ref=app ---> WINNER IS YSRAELCON: https://code.sololearn.com/W9GYDCnBW7Bq/?ref=app TASK: A 'quark-pair' is an integer pair. First you have to convert a number x into binary and count the 1's. Now multiply the number of 1's with x and store the product. We call two numbers a 'quark-pair' if their products are equal! HAVE FUN !!!

13th Aug 2017, 7:53 PM
Julian Fechner
Julian Fechner - avatar
176 Antworten
+ 24
WOW. YOU ALL DID A VERY GOOD JOB!!! CONGRATULATION TO YOU ALL AND THANKS FOR #COTD! I'M GLAD THAT YOU LIKE THE CHALLENGES. HOPE I'LL SEE YOU AGAIN IN THE NEXT CHALLENGE: https://www.sololearn.com/discuss/626739/?ref=app
14th Aug 2017, 8:41 PM
Julian Fechner
Julian Fechner - avatar
13th Aug 2017, 8:33 PM
Maz
Maz - avatar
+ 28
me too, here my try: https://code.sololearn.com/W9GYDCnBW7Bq/?ref=app testing time on phone with 1 up to: 5000 in a trice. 10000 in a blink. 20000 in a breath. thanks to @Maz and @Garikai, which gave me an idea for my try. And @Vari93 that encourage me for save the place in my answer meanwhile I was resolving it ☺. And @Ready for notify me that could make it a bit faster. And @VcC for a improved version .👍
13th Aug 2017, 10:27 PM
ysraelcon
ysraelcon - avatar
+ 25
python. lists all pairs up to given value. can do up to about n=5000 before it starts to time out. fun challenge ☺ https://code.sololearn.com/c9HK4CazDwxT/?ref=app
13th Aug 2017, 9:48 PM
Ready
Ready - avatar
+ 18
Here's my try (Web version) https://code.sololearn.com/W25d6BU6Eb38/?ref=app I gave it my best shot ^^
14th Aug 2017, 1:10 PM
MizoPro
MizoPro - avatar
+ 16
Here is mine. Optimized & using a reverse table for quicker results. No time limit for n=4000. See also my quark2 version working up to n=8000. https://code.sololearn.com/c0OQHJSeKVuF/?ref=app
14th Aug 2017, 12:17 PM
VcC
VcC - avatar
+ 12
Although not any such pairs info found on google, but tried the coding as told. see it. (CLEARLY INTERPRETABLE)...perhaps https://code.sololearn.com/cSIvNjiFSF7P/?ref=app
14th Aug 2017, 4:17 PM
Hari K
+ 12
include <iostream.h> using namespace std; int solution ( int num) { int i,count=0; for (i=0;i < (sizeof (int)*8 -1);i++) { if ( num<<i & 1 ) { count++; } } return num*count; } void main (){ int n,m; cin>>n; cin>>m; if ( solution (n) == solution (m) ) { cout <<" yes"; } else { cout <<" no"; } }
14th Aug 2017, 6:31 PM
Mohammad Aasim
+ 10
Here we go. Skipped exception handling for concision https://code.sololearn.com/cWxF5EOpiz2F/?ref=app
13th Aug 2017, 9:44 PM
Garikai
Garikai - avatar
14th Aug 2017, 6:08 PM
Shivani
Shivani - avatar
15th Aug 2017, 8:31 PM
David Akhihiero
David Akhihiero - avatar
+ 9
here is working code in c online link of this program : https://pastebin.com/tAd0Cuqc #include<stdio.h> int bin(int ); int bin(int n) //this fn returns product { int i=0,j,n1,t,arr[100],count=0; t=n; while(n!=0) { n1=n%2; n=n/2; arr[i++]=n1; } for(j=i-1;j>=0;j--) { if(arr[j]==1) count=count+1; } return count*t; } int main() { int n,i,j,y,z; printf("Enter value of n:"); scanf("%d",&n); for(i=0;i<=n;i++) { y=bin(i); for(j=i+1;j<=n;j++) { z=bin(j); if(y==z) { printf("Quarks pair: %d %d\n" ,i,j); } } } }
14th Aug 2017, 2:43 AM
Amrendra Kumar
Amrendra Kumar - avatar
+ 9
I think SL challenges should be like this only and not the quizzes. 🤔🤔
14th Aug 2017, 3:42 PM
Ritish Shrirao
Ritish Shrirao - avatar
+ 9
Will I ever reach a point to solve such challenges
14th Aug 2017, 4:11 PM
Rodgers
Rodgers - avatar
14th Aug 2017, 4:50 PM
Erik Johanson
Erik Johanson - avatar
+ 9
https://code.sololearn.com/crBC39X9oXbj/?ref=app
14th Aug 2017, 5:10 PM
davy hermans
davy hermans - avatar
+ 8
Here is my java code for finding Quark pairs.. Upvote if you like... https://code.sololearn.com/cjoMsHtxhKYu/?ref=app
14th Aug 2017, 3:27 PM
Shubham Choudhary
Shubham Choudhary - avatar
15th Aug 2017, 12:50 PM
Sai Satyam
+ 7
Here is mine. For some reason, I get time limit exceeded on very low numbers, like 33, but I have tested this on my computer, and it definitely runs fairly quickly, ran on 5000 in under a second, 10000 in just over a second, and 1000000 in about 6 or 7 seconds. The code playground is highly, highly inefficient lol. But this does work, and it checks for valid input. https://code.sololearn.com/c942sw8xFP1X/?ref=app
14th Aug 2017, 4:03 AM
Vari93
Vari93 - avatar