只須要按照題目暴力算就完事了,最後結果是2658417853,代碼以下:c++
#include <bits/stdc++.h> typedef long long ll; bool judge(ll a){ while(a){ //將a的每一個位都進行判斷,符合條件直接跳出 if(a<10){ if(a==2||a==1||a==9){ return true; } else return false; } int k=a%10; if(k==0||k==2||k==1||k==9) return true; a/=10; } return false; } int main(){ ll sum=0; for(int i=1;i<=2019;++i){ if(judge(i)) sum+=(i*i); } std::cout<<sum<<std::endl; return 0; }