出现13且能被13整除
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<functional>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 20;
typedef __int64 Int64;
int n;
int dp[maxn][maxn][3];
int digit[maxn];
int dfs( int pos,int st,bool flag,int mod )
{
if( !pos ) return mod == 0 && st == 2;
if( flag && dp[pos][mod][st] != -1 ) return dp[pos][mod][st];
int ans = 0;
int u = flag?9:digit[pos];
for( int i = 0; i <= u; i ++ )
{
if( st == 2 || ( st == 1 && i == 3 ) ) ans += dfs( pos-1,2,flag||i<u,(mod*10+i)%13 );
else if( i == 1 ) ans += dfs( pos-1,1,flag||i<u,(mod*10+i)%13 );
else ans += dfs( pos-1,0,flag||i<u,(mod*10+i)%13 );
}
if( flag ) dp[pos][mod][st] = ans;
return ans;
}
int fun( int x )
{
int len = 0;
while( x ){
digit[++len] = x%10;
x /= 10;
}
return dfs( len,0,0,0 );
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
memset( dp,-1,sizeof(dp) );
while( scanf("%d",&n) != EOF )
{
printf("%d\n",fun(n));
}
return 0;
}