攻克lightoj基礎題系列
給你兩個數(在本題中5代表的數是12345為1到五的等差數列,其他數也如此),求兩個數之間三的倍數的數的個數,明顯的暴力逾時,但規律易得,每三個數内都有兩個數為三的倍數,把情況讨論一下就可以了。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
for (int k = ; k <= t; ++k)
{
int a, b;
scanf("%d%d", &a, &b);
int ans = ;
if (a % == )
{
ans++;
}
else if (a % == )
{
ans += ;
a += ;
}
else
{
ans += ;
a++;
}
if (b % == )
{
}
else if (b % == )
{
b--;
}
else
{
ans++;
b -= ;
}
ans +=(b - a) / * ;
printf("Case %d: %d\n", k, ans);
}
return ;
}