Matrix(数学,子串和,矩阵,数因子)

You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells(i, j) that are the elements of the rectangle equals a in each rectangle.

A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such thatx ≤ i ≤ y, z ≤ j ≤ t.

Input

The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).

Output

Print a single integer — the answer to a problem.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Examples
input
10
12345
output
6
input
16
439873893693495623498263984765
output
40

思路:
给你一串数字,只需求出他的子串和(等于给出数字的因子),求出个数。
注意,0的优化。

代码:
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
LL a[4000+10];
LL b[50005+10];
int main()
{
    string s;
    int k;
    cin>>k>>s;
    int len=s.size();
    for(int i=0;i50000)
                    continue;
                else
                    sum+=b[i]*b[tm];
            }
        }
    }
    printf("%lld\n",sum);
}


 
          


 
          



你可能感兴趣的:(ACM竞赛,【含有数学思想】,ACM的进程)