Hdoj 5211 mutiple "Water"

Source: Internet
Author: User

MutipleTime limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): Accepted submission (s): 45


Problem Descriptionwld likes playing with a sequence a[1.. N] . One day he's playing with a sequence of N Integers. For every index I, WLD wants to find the smallest index F(i) (if exists), that i<F(i)≤n , and aF(i) MoD a i = 0. If There is no such an index F(i) , we set F(i) As 0.
Inputthere is multiple Cases. (At most ten )

For each case:

The first line contains one integers < Span class= "Mrow" id= "mathjax-span-56" style= "" >n 1 ≤ N ≤ 10000 ) .

The second line contains N Integers a1,a2,...,aN (1≤aI≤10000) , denoting the sequence WLD plays with. You can assume this all AI is distinct.
Outputfor each case:

Print one integer. It denotes the sum of all F(i) For all 1≤i<n
Sample Input
41 3 2 4

Sample Output
6HintF (1) =2f (2) =0f (3) =4f (4) =0

Sourcebestcoder Round #39 ($) test instructions: asks for the sum of the middle smallest number greater than I (1~n-1) less than or equal to n

Code:

#include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <set > #define LL __int64using namespace Std;const ll Mod = 10007;const ll M = 1e4+5;int s[m];int main () {    int n;    while (scanf ("%d", &n) = = 1) {        memset (s, 0, sizeof (s));        for (int i = 1; I <= n; + + i) {            scanf ("%d", &s[i]);        }        int sum = 0;        for (int i = 1; i < n; + + i) {            int Min = 1e7;            for (int j = i+1; J <= N; + + j) {                if (s[j]%s[i] = = 0&&min > J) {                    Min = j;                }            }            if (min! = 1e7) sum + = Min;         }        printf ("%d\n", sum);    }    return 0;}



Hdoj 5211 mutiple "Water"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.