洛谷 P1424 小鱼的航程(改进版)

之前没过的题目拿出来看看。。
测评地址:https://www.luogu.org/problemnew/show/P1424
通过时间:2019.3.22
耗时/内存:29ms, 808KB
洛谷 P1424 小鱼的航程(改进版)
错误示范:

//错误示范,会超时 
#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
	long long x,n,b,r=0,i;
	scanf("%lld %lld",&x,&n);
	int a[7]={250,250,250,250,250,0,0};
	for(i=0;i<n;i++)
	{
		b=x+i-1;
		while(b>6)
		{
			b-=7;
		}
		r+=a[b];
	}
	cout<<r;
	return 0;
 } 

AC代码:

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
	long long x,n,ans=0,i;//周x n天 
	scanf("%lld %lld",&x,&n);
	for(i=0;i<n;i++)
	{
		if(x!=6 and x!=7) ans+=250;
		if(x==7) x=1;
		else x++;
	}
	cout<<ans;
	return 0;
 }