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"