2018-05-25 21:10:37

30分代码

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define R register
using namespace std;
typedef long long ll;
bool pd(ll );
ll a,b;
ll ans;

int main() {
scanf("%lld%lld",&a,&b);
for(R ll i = 1;i <= a*b;++i) {
if(pd(i)) continue;
ans = max(i,ans);
}
printf("%lld\n",ans);
return 0;
}

bool pd(ll n) {
for(R ll i = 0;n - i >= 0;i += a) {
ll a1 = n - i;
for(R ll j = 0;a1-j >= 0;j += b) {
ll b2 = a1 - j;
if(b2 == 0) return true;
}
}
return false;
}


60分代码

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define R register
using namespace std;
typedef long long ll;
bool pd(ll );
ll a,b;
ll ans;

int main() {
scanf("%lld%lld",&a,&b);
for(R ll i = a*b;i >= 1;--i) {
if(pd(i)) continue;
else {
printf("%d\n",i);
return 0;
}
}
return 0;
}

bool pd(ll n) {
if(n % a == 0 || n % b == 0) return true;
for(R ll i = 0;n - i >= 0;i += a)
if((n - i) % b == 0) return true;
return false;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
ll a,b;
scanf("%lld%lld",&a,&b);
printf("%lld\n",a*b-a-b);
return 0;
}

• star
首页