QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487052#5344. Odd and Even ZeroesPetroTarnavskyi#AC ✓2ms3636kbC++201.0kb2024-07-22 15:36:232024-07-22 15:36:24

Judging History

你现在查看的是最新测评结果

  • [2024-07-22 15:36:24]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3636kb
  • [2024-07-22 15:36:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

PLL f(int k)
{
	if (k == 0)
		return {1, 0};
	auto [f0, f1] = f(k -1);
	if (k % 2 == 1)
		return {5 * f0, 5 * f1};
	else
		return {3 * f0 + 2 * f1, 3 * f1 + 2 * f0};
}

LL solve(LL n, int t)
{
	if (n == 0)
		return 0;
	int pw = 0;
	LL val = 1;
	while (val * 5 <= n)
	{
		pw++;
		val *= 5;
	}
	auto [f0, f1] = f(pw);		
	return (t == 0 ? f0 : f1) + solve(n - val, t ^ (pw % 2));
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	while (true)
	{
		LL n;
		cin >> n;
		if (n == -1)
			return 0;
		cout << solve(n + 1, 0) << '\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

input:

2
3
10
100
1000
2000
3000
10000
100000
200000
-1

output:

3
4
6
61
525
1050
1551
5050
50250
100126

result:

ok 10 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3492kb

input:

1807332722
817262418
986852752
493442298
734402612
191460341
1615843100
579526248
776247863
190158456
1882551618
1488678126
1885303503
415085162
1391030569
1596443829
490300179
1663490266
911893976
1959159065
1793979508
265301379
457629615
1382946943
1137064540
82942688
293372541
277413468
311026117...

output:

903689458
408657094
493459575
246737995
367226243
95730380
807945536
289779975
388154519
95080432
941294774
744366875
942672429
207554165
695550015
798248030
245166970
831775957
455973362
979593715
897010729
132663155
228824720
691507779
568569600
41473739
146701567
138719505
155526545
780003180
263...

result:

ok 1000 lines