比赛 [不是Rapiz出的]农场主钦定NOIP模拟赛1 评测结果 AAAAAAAAAA
题目名称 Rabbit Number 最终得分 100
用户昵称 Kulliu 运行时间 0.000 s
代码语言 C++ 内存使用 0.09 MiB
提交时间 2016-11-08 21:05:36
显示代码纯文本
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cstdio>
#include<vector>
#include<queue>
#include<ctime>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;
typedef long long LL;
#define F(i,l,r) for(LL i=l;i<=r;i++)
#define D(i,r,l) for(LL i=r;i>=l;i--)
inline int work(LL x) {
	int cnt = 0;
	while(x)
	    cnt+=x%10,x/=10;
	return cnt;
}
int Main(){
    freopen("rabbits.in","r",stdin);
	freopen("rabbits.out","w",stdout);
	queue<LL>q;
	LL l,r,ans=0;
	scanf("%lld%lld",&l,&r);
	q.push(0);
	while(!q.empty()) {
		int now=q.front();q.pop();
		if(now>r)break;
		if(now>=l)ans++;
		F(i,0,3){
			if(!now&&!i)continue;
			LL x=now*10+i,tmp=work(x);
			if(tmp*tmp==work(x*x))
			    q.push(x);
			else break;
		}
	}
	printf("%d\n",ans);
}
int start=Main();
int main(){;}