here is my code.
Code: Select all
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <list>
#include <vector>
#include <map>
using namespace std;
long long BinarySearch(long long low, long long high, long long val, long long rate)
{
if(high<=low) return low;
long long mid = (low+high)/2;
long long x = mid - ((double)rate/100)*(double)mid;
if(x<=val) return BinarySearch(mid+1, high, val, rate);
else return BinarySearch(low, mid-1, val, rate);
}
int main()
{
long long m, rate;
while(scanf("%lld %lld",&m,&rate) && m)
{
if(!rate || rate == 100LL) printf("Not found\n");
else
{
long long min = m-1;
double deduct = ((double)rate/100.0)*(double)m;
long long x = m - deduct;
if(x>=min)
{
printf("Not found\n"); continue;
}
m += deduct;
x = m - ((double)rate/100)*(double)m;
while(x<=min)
{
m += deduct;
x = m - ((double)rate/100.0)*(double)m;
}
m = BinarySearch(m-deduct, m, min, rate);
x = m - ((double)rate/100)*(double)m;
while(x<min)
{
m++;
x = m - ((double)rate/100.0)*(double)m;
}
while(x>=min)
{
m--;
x = m - ((double)rate/100.0)*(double)m;
}
printf("%lld\n",m);
}
}
}