10830 - A New Function
Moderator: Board moderators
-
- New poster
- Posts: 9
- Joined: Sun Mar 13, 2005 11:41 am
10830 - A New Function
Hello.Can somebody tell me how to solve this problem.
I find formula for SOD.I find formula for CSOD too but it takes N operations.I do it another way and came up to the problem of finding sum of reminders 1 to n.
Please help me give some hint.
I find formula for SOD.I find formula for CSOD too but it takes N operations.I do it another way and came up to the problem of finding sum of reminders 1 to n.
Please help me give some hint.
I don't know what formulas your have now so I just talk about my logic.
Although the detail may be different from each person, but the logic should be similar:
To find CSOD you can sum some function O(1) f(x, N) from 1 to N, that is,
CSOD(N) = f(1,N)+f(2,N)+...+f(N,N)
In my code, the values f(x,N) will repeat many times when x > root(N), so I don't add each term f(x,N) slowly when x > root(N). Instead, I find out how many values of x will make f(x,N) = k of a certain value in O(1), then I use multiplication to sum these f(x,N) to the answer.
Although the detail may be different from each person, but the logic should be similar:
To find CSOD you can sum some function O(1) f(x, N) from 1 to N, that is,
CSOD(N) = f(1,N)+f(2,N)+...+f(N,N)
In my code, the values f(x,N) will repeat many times when x > root(N), so I don't add each term f(x,N) slowly when x > root(N). Instead, I find out how many values of x will make f(x,N) = k of a certain value in O(1), then I use multiplication to sum these f(x,N) to the answer.
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
I've tested my solution with bruteforce for N < 1000000, but I cannot get the right answer for 2 billion. I also cannot detect any overflows (or underflows).. can someone lend me some insight and/or test cases? Thanks.
Check out http://www.algorithmist.com !
Hello.
I dont think it's hard to find this formula.
CSOD(n)=P-n+1 P=((n div 2)-1)*2+((n div 3)-1)*3 +...+((n div n)-1)*n
But for calculating it I must do N operations,it is too slow.Can this formula calculated faster?
Eduard
I dont think it's hard to find this formula.
CSOD(n)=P-n+1 P=((n div 2)-1)*2+((n div 3)-1)*3 +...+((n div n)-1)*n
But for calculating it I must do N operations,it is too slow.Can this formula calculated faster?
Eduard
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
I don't understand your previous post well.
Thanks.
For wich K are you doing it?What is time complexity of your program?I find out how many values of x will make f(x,N) = k of a certain value in O(1)
Thanks.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
In my previous post I don't want to give too much detail as I don't want to write spoiler..... Here is the detail:
The value of "n div x" will repeat when x becomes larger, and when x > root(N), n div x <= root(N), and I just try all such n div x as value K.
And so the complexity is root(N)
Code: Select all
CSOD(n)=((n div 2)-1)*2+((n div 3)-1)*3 +...+((n div n)-1)*n
=(n div 2)*2 + (n div 3)*3 + ..... + (n div n)*n - sum(2,n)
And so the complexity is root(N)
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
Now i got it.
Thanks.
Thanks.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
What's the answer for:
I get:
Code: Select all
1000000
2000000
1000000000
Code: Select all
322466618438
1289867461381
322467032612360629
Check out http://www.algorithmist.com !
Well, my answer isLarry wrote:What's the answer for:
I get:Code: Select all
1000000 2000000 1000000000
Code: Select all
322466618438 1289867461381 322467032612360629
Code: Select all
Case 1: 322466618438
Case 2: 1289867461381
Case 3: 322467032612360629

(In other words, the numbers are correct, but are you writing also the case numbers correctly?)
I obtain the same results,
What is the output for this, please:
Thanks in advance
What is the output for this, please:
Code: Select all
0
1
2000000000
1347838239
123848
137587
38495969
34888888
1234923
40
41
42
1000
2000
1000000
2000000
10000000
20000000
100000000
249999999
249999997
-
- New poster
- Posts: 5
- Joined: Wed Mar 16, 2005 1:40 am
- Location: Brazil
"Input is terminated by a line where the value of n=0. This line should not be processed."
I didn't read the problem very well the first time and got some WA because of this. The sample input doesn't have a 0 at the end
Input:
Output:
I didn't read the problem very well the first time and got some WA because of this. The sample input doesn't have a 0 at the end

Input:
Code: Select all
1
2000000000
1347838239
123848
137587
38495969
34888888
1234923
40
41
42
1000
2000
1000000
2000000
10000000
20000000
100000000
249999999
249999997
0
Code: Select all
Case 1: 0
Case 2: 1289868132101422932
Case 3: 585815512116088361
Case 4: 4945965530
Case 5: 6104124608
Case 6: 477876619598302
Case 7: 392517961466207
Case 8: 491771668356
Case 9: 483
Case 10: 483
Case 11: 536
Case 12: 321582
Case 13: 1288012
Case 14: 322466618438
Case 15: 1289867461381
Case 16: 32246696794797
Case 17: 128986798547827
Case 18: 3224670272194238
Case 19: 20154189031290875
Case 20: 20154188822204538
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
misof: thanks, actually, I wasn't on a machine I can code on, so I wrote it in PERL to see if my formula's working. Actually, I never submitted, because I thought it didn't match the sample output, but I finally read the sample input correctly, and it's 200 million, not 2 billion! Talk about stupid mistake!
Check out http://www.algorithmist.com !
WHY WA?
For this input
I get this output:
I think it's right, isn't it???
Code: Select all
1
2
3
4
5
6
7
8
9
10
0
Code: Select all
Case 1: 0
Case 2: 0
Case 3: 0
Case 4: 2
Case 5: 2
Case 6: 7
Case 7: 7
Case 8: 13
Case 9: 16
Case 10: 23
Last edited by Andrey on Wed Mar 23, 2005 4:10 pm, edited 1 time in total.