According to the meaning of the questions simulated violence hit the table to find the law, noted that: meet the meaning of the title number contains only \ (0,1,2,3 \) , greater than \ (3 \) number, the square will carry, carry lead to \ (S (x) * S ( x) <S (x * x) \)
Observation data range, digital greatest satisfaction that Italy has \ (10 \) position, then we enumerate the numbers on each one, and then determine whether the number of violent rabbit on the line.
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define Mi return
#define manchi 0
using namespace std;
inline int read()
{
int num=0,w=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
while(isdigit(ch)) num=(num<<1)+(num<<3)+ch-'0',ch=getchar();
Mi num*w;
}
int l,r,ans;
long long tmp1,tmp2;
inline int cal(long long x)
{
int res=0;
while(x)
{
res+=x%10;
x/=10;
}
return res;
}
int main()
{
l=read();r=read();
for(int a1=0;a1<=3;a1++)
for(int a2=0;a2<=3;a2++)
for(int a3=0;a3<=3;a3++)
for(int a4=0;a4<=3;a4++)
for(int a5=0;a5<=3;a5++)
for(int a6=0;a6<=3;a6++)
for(int a7=0;a7<=3;a7++)
for(int a8=0;a8<=3;a8++)
for(int a9=0;a9<=3;a9++)
for(int a10=0;a10<=3;a10++)
{
tmp1=a1*1e8+a2*1e7+a3*1e6+a4*1e5+a5*1e4+a6*1e3+a7*1e2+a8*10+a9+a10*1e9;
if(tmp1<l || tmp1>r) continue;
tmp2=1LL*tmp1*tmp1;
if(cal(tmp1)*cal(tmp1)==cal(tmp2)) ans++;
}
printf("%d",ans);
Mi manchi;
}