We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int take_element_4_1 (int a, int b) {
int count=0;
int res=0;
if(b<10) return 0;
else if (b>9 && b<100)
{
res=a-b;
if (res%1000 !=0 ) return 0;
else return res/1000;
}
else
{
while (a)
{
if (a%10==b%10) {
a/=10;
b/=10;
count ++;
}
else {
res= res*10+a%10;
a/=10;
}
}
if (count==3) return res;
else return 0;
}
}
int check_last_case (int a,int b ,int x,int y )
{
if (x<10 || y<10 ) return 0;
else if (x <100 && y<100 )
{
a=take_element_4_1(a,x) ;
b=take_element_4_1(b,y) ;
if (a==0 || b==0) return 0;
else return (a==b);
}
else {
a=take_element_4_1(a,x);
b=take_element_4_1(b,y);
if (a==0 || b==0) return 0;
else if (a>10 || b>10) return 0;
else return (a==b);
}
}
main()
int i=1;
while (i <= 998) {
int j = i + 1;
if (j >= 10 * i)
i++;
else {
while (j <= 999) {
if (GCD(i, j) > 1)
j++;
else {
int cnt = 1000 / i + 1;
while (j * cnt <= 9999) {
for (int u = 1; u <= 999 / j; u++) {
if (check_last_case(i * cnt, j *cnt, i * u, j * u)) {
if (d[i * cnt][j * cnt] == 0) {
numerator += i * cnt;
denominator += j * cnt;
}
d[i * cnt][j * cnt]++;
}
}
cnt++;
}
j++;
}
}
i++;
}
}
cout<<numerator<<" "<<denominator;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #33: Digit canceling fractions
You are viewing a single comment's thread. Return to all comments →
int take_element_4_1 (int a, int b) { int count=0; int res=0; if(b<10) return 0; else if (b>9 && b<100) { res=a-b; if (res%1000 !=0 ) return 0; else return res/1000; } else { while (a) { if (a%10==b%10) { a/=10; b/=10; count ++; } else { res= res*10+a%10;
a/=10;
}
}
int check_last_case (int a,int b ,int x,int y ) {
}
main() int i=1;