A. Anagrams
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard 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.

Sample test(s)
input
3
output
1 2
input
9
output
1 2 4 8
input
33
output
1 2 4 8 16 32

题意:给出一个进制b,有一数字k,有某种性质。
性质:这个数x整除于k,且在b进制下长度相等与x相等的所有数都能被k整除。
求对于这个b,所有满足这个性质的数。
分析:
1、找规律,b-1的所有因数既是答案
2、证明一下。
显然不能等于b。k=b,x=k就是一个反例。
若大于b,也是不科学的。因为x=b*k是一个反例
若小于b,那么对于长度相等这一条件,可以当成原来有一个可以整除的,任意交换两个数位,仍然整除。。。

bp*b^p+bp-1*b^(p-1)+.....+bi*b^i+......+bj*b^j+......b0*b^0 = 0 (mod k) ............ 1
bp*b^p+bp-1*b^(p-1)+.....+bj*b^i+......+bi*b^j+......b0*b^0 = 0 (mod k) ............... 2
若两式都是k的倍数,可知1式-2式也是k的倍数。
则(bi * b^i + bj * b^j) - (bj * b^i + bi * b^j)是k的倍数。
(bi * b^i + bj * b^j) - (bj * b^i + bi * b^j)
= (bi - bj) * (b^i - b^j)
= (bi - bj) * b^j * (b^(i - j) - 1)
这个(b^(i - j) - 1)肯定是b-1的正整倍数。
那么,当k|b-1的时候,显然成立。
否则就是每个位相等。。。。 如果每个位相等,
k = number * (b^p+b^(p-1)+......+b^2+b^1+1)
与k是一个不大于b的正整数矛盾。不科学。 所以k必定是b-1的因数。

 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} int n; inline void Input()
{
cin >> n;
} inline void Solve()
{
n--;
vector<int> ans;
for(int i = ; i <= n; i++)
{
if(n / i < i) break;
if(n % i == )
{
ans.pub(i);
if(n / i != i) ans.pub(n / i);
}
}
sort(ans.begin(), ans.end());
int length = sz(ans);
for(int i = ; i < length; i++)
printf(i < length - ? "%d " : "%d\n", ans[i]);
} int main()
{
Input();
Solve();
return ;
}

ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 A. Anagrams的更多相关文章

  1. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

  2. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

  3. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 I. Illegal or Not?

    I. Illegal or Not? time limit per test 1 second memory limit per test 512 megabytes input standard i ...

  4. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout

    K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...

  5. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 H. Hashing

    H. Hashing time limit per test 1 second memory limit per test 512 megabytes input standard input out ...

  6. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 C. Colder-Hotter

    C. Colder-Hotter time limit per test 1 second memory limit per test 512 megabytes input standard inp ...

  7. hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...

  8. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  9. Moscow Subregional 2013. 部分题题解 (6/12)

    Moscow Subregional 2013. 比赛连接 http://opentrains.snarknews.info/~ejudge/team.cgi?contest_id=006570 总叙 ...

随机推荐

  1. NYOJ题目111分数加减法

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsEAAAKBCAIAAAA5i+FPAAAgAElEQVR4nO3dPXLbugMv7LsJ916Iay ...

  2. NYOJ题目64鸡兔同笼

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsAAAAIZCAIAAAAnfB5fAAAgAElEQVR4nO3dO1LjygIG4LsJchZC7I ...

  3. Hibernate中一对多和多对一关系

    1.单向多对一和双向多对一的区别? 只需要从一方获取另一方的数据时 就使用单向关联双方都需要获取对方数据时 就使用双向关系 部门--人员 使用人员时如果只需要获取对应部门信息(user.getdept ...

  4. 缓慢变化维 (Slowly changing dimension)

          维度建模的数据仓库中,有一个概念叫Slowly Changing Dimensions,中文一般翻译成"缓慢变化维",经常被简写为SCD.缓慢变化维的提出是因为在现实世 ...

  5. HDU3364 Lanterns(求矩阵的秩)

    求矩阵的秩,及判断有无解 #include<cstdio> #include<iostream> #include<cstdlib> #include<cst ...

  6. EasyUI - DataGrid 去右边空白滚动条列 分类: JavaScript 2014-09-03 10:46 1090人阅读 评论(2) 收藏

    熟悉 EasyUI - DataGrid 的童鞋应该会注意到这样一个情景: 想去掉这块,找了下资料,发现也有人同样纠结:http://www.cnblogs.com/hantianwei/p/3440 ...

  7. Oracle Segments可以跨多个data files吗?

    首先,你需要明白的一点是:数据库的物理结构是由数据库的操作系统文件所决定,每一个Oracle数据库是由三种类型的文件组成:数据文件.日志文件和控制文件.数据库的文件为数据库信息提供真正的物理存储.每一 ...

  8. html5 基本布局+新标签+新选择器 + 线性渐变

    html5 基本布局+新标签 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  9. 6-03使用SQL语句一次型向表中插入多行数据

    通过将现有表中的数据添加到已存在的表中: INSERT INTO <表名><列名> SELECT<列名> FROM<源表名> 将UserInfo的数据添 ...

  10. PHP导出Excel一个方法轻松搞定

    /** * 导出数据为excel表格 *@param $data 一个二维数组,结构如同从数据库查出来的数组 *@param $title excel的第一行标题,一个数组,如果为空则没有标题 *@p ...