###### ACM,deep love

to be with interesting people && problems

###### 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest A

A. Anagrams
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Consider the positional numeral system with a given base b. A positive integer x is called b-anagram of a positive integer y if they have the same length of representation in this system (without leading zeroes) and y can be obtained by rearranging the digits of x.

A positive integer k is called b-stable if for every integer m that is divisible by k all its b-anagrams are also divisible by k. Your task is to find all b-stable integers k for a given base b.

Input
The only line of the input contains an integer b — the base of the given positional numeral system (2 ≤ b ≤ 2·109).

Output
Print all b-stable integers k represented in the standard decimal numeral system. They must be printed in ascending order.

Examples
input
3
output
1 2
input
9
output
1 2 4 8
input
33
output
1 2 4 8 16 32

// ml:run = \$bin < input
#include <iostream>
#include <set>

using ll = long long;
ll b;

int main()
{
std::ios_base::sync_with_stdio(false);
std::cin >> b;
b--;
std::set<int> ans;
ans.insert(1);
ans.insert(b);
for (ll i = 2; i * i <= b; i++)
if (b % i == 0) {
ans.insert(i);
ans.insert(b / i);
}
for (auto i : ans) std::cout << i << " ";
}

#### 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest A题：Anagrams [打表/规律题]

2015-10-24 19:18:16

#### (Relax ST1.7)POJ 1256 Anagram(求一个字符串在特殊规定下的全排列)

2013-11-26 10:15:05

#### poj 1256（Anagram）

2015-03-18 23:09:17

#### 找出一个字符串的所有anagram

2012-10-02 13:07:24

#### POJ1256 Anagram(回溯法)

2016-02-17 21:44:16

#### Anagram(匹配-山东省省赛-贪心)

2018-05-21 07:07:45

#### POJ 1256 Anagram

2010-07-24 09:49:00

#### EOJ Monthly 2017.12 C.易位构词 (anagram)(模拟)

2017-12-09 19:37:22

#### ACM基础与精选２０１８

2018-01-31 07:54:16

#### poj1256 Anagram (next_permutation())

2016-01-09 18:52:29

## 不良信息举报

2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest A