0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Atcoder解いてみた AtCoder Beginner Contest C - Cream puff

0
Posted at

AtCoder Beginner Contest C - Cream puff

問題はこちら

回答

コードの通りO(√N logN)で実装可能
set使わなければO(√N)

#include <iostream>
#include <string>
#include <map>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <limits.h>
#include <bitset>
#include <list>
#include <set>
#include <numeric>
#include <tuple>

long long N;

int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);

	std::cin >> N;

	std::set<long long> ans;
	for (long long i = 1; i * i <= N; i++) {
		long long remain = N % i;
		long long div = N / i;
		
		if (remain != 0) {
			continue;
		}

		ans.insert(i);
		ans.insert(div);
	}
	
	for (auto itr = ans.begin(); itr != ans.end(); itr++) {
		std::cout << *itr << std::endl;
	}
	return 0;
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?