• A


    A - Matrix
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    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 that x ≤ 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.

    Sample Input

    Input
    10
    12345
    Output
    6
    Input
    16
    439873893693495623498263984765
    Output
    40
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 4010;
    char s[maxn];
    LL b[maxn][maxn];
    LL sum[maxn];
    map<LL,LL> mp;
    int main() 
    {
        //freopen("in.txt","r",stdin);
        LL a;
        while(cin>>a)
        {
            scanf("%s",s+1);
            int len = strlen(s+1);
            int n  = len;
            LL ans = 0;
            sum[0] = 0;
            LL cnt = 0;
            repf(i,1,n)
                sum[i] = sum[i - 1] + s[i] - '0';
            
            repf(i,1,n)
                repf(j,i,n)
                {
                    LL temp = sum[j] - sum[i-1];
                    mp[temp] = mp[temp] + 1;
                }
            
            if(a == 0)
            {
                rep(i,1,50000)
                    ans += mp[0]*mp[i];
                ans *= 2;
                ans += mp[0]*mp[0];
                cout<<ans<<endl;
                continue;
            }
            for(LL i = 1;i < 50000;++i)
            {
                if(a%i == 0)
                {
                    ans += mp[i]*mp[a/i];
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }
     
  • 相关阅读:
    Python M3 面向对象
    Python 基础
    Python 基础
    Python 基础
    Python 作业
    Python 基础
    Python 基础
    【机器学习】周志华 读书笔记 第三章 线性模型
    【机器学习】周志华 读书笔记 第二章 模型评估与选择
    【机器学习】周志华 读书笔记 第一章 绪论
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3444549.html
Copyright © 2020-2023  润新知