Moderator: Board moderators
Each line contains a single 64-nit signed integer which denotes the value of n.
long long N = 0, n, res, nn;
while (1) {
scanf("%lld", &N);
if (N == 0) return 0;
if (N % 2 == 0) N --;
n = floor(sqrt(N)) - 1;
res = (n *( n + 1)) / 2;
if ( res % 3 == 0) {
res = (res / 3 ) * ( 2 * n + 1);
}
else {
res *= (2 * n + 1 ) / 3;
}
nn = (n + 1) / 2 ;
res += nn * nn;
n ++;
nn = n * n;
if (nn % 2 == 0 ) nn ++;
printf("%lld\n", (res + n * (1 + ( N - nn) / 2))%100000000); 1
2
3
1000000000
9223372036854775807
100000000000000000
99999999999999999
123654789
1234567890
9876543210
4611686018427387903
0
1
1
2
75541908
-44674654
-3521044
-3521044
16899320
22630176
16080030
-85450240
1
1
2
75541908
83293346
28651756
28651756
16899320
22630176
16080030
82064896
4611686018427387903
0
82064896
My AC code returns 82064896 for Piklu_sust's last input.
INPUT:
Code:
4611686018427387903
0
CORRECT OUTPUT:
Code:
82064896
1
2
3
9
19
29
1000
1001
1002
1003
1334455667788
10000000001
10000000015
9223372036854775807
100000000000000000
99999999999999999
123654789
1234567890
9876543210
4111686018427387101
2223372036854771111
1223372036854771111
4223372036854771002
5223372036854771001
6223372036854771000
9223372036854775797
9223372036854775798
9223372036854775799
9223372036854775800
9223372036854775801
9223372036854775802
9223372036854775803
9223372036854775804
9223372036854775805
9223372036854775806
9223372036854775807
0
1
1
2
9
26
49
10300
10331
10331
10362
5930690
33450000
34150000
83293346
28651756
28651756
16899320
22630176
16080030
69193482
77177890
63675584
18804889
33788440
87246958
98290851
98290851
35291350
35291350
72291849
72291849
9292348
9292348
46292847
46292847
83293346
We cannot have negative numbers as input, right?
I assume in my program that the correct inputs are integers in the closed interval [1, 2^63-1].
I have no idea what's wrong. Any ideas are welcome.
piklu.cse@gmail.com
Sedefcho wrote:I didn't understand quite well what you mean here:
If there is subtraction in your code, try to make this
in terms of addition something. (I don't know what you do).
Users browsing this forum: No registered users and 0 guests