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. 自定义Log模块

    BuildConfig.DEBUG默认为true,在为app打上SignedKeyStore之后就为false, // Log控制器 MyLoger.openDebutLog(true); MyLog ...

  2. 51nod1069(nim博弈)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1069 题意: 中文题诶~ 思路: 一开始我以为需要把上一堆到 ...

  3. 借助LinkedHashMap实现基于LRU算法缓存

    一.LRU算法介绍 LRU(Least Recently Used)最近最少使用算法,是用在操作系统中的页面置换算法,因为内存空间是有限的,不可能把所有东西都放进来,所以就必须要有所取舍,我们应该把什 ...

  4. hdu 4006 The kth great number

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 思路:利用优先队列的性质,将数据存入后会自动对数据进行排序 #include<stdlib ...

  5. NMON中的各项参数指标

    一.NMON中的各项参数指标: SYS_SUMM:显示当前服务器的总体性能情况 Total System I/OStatistics:Avg tps during an interval:显示采集间隔 ...

  6. MVC学习笔记---MVC框架执行顺序

    一.把路由添加到路由表, 二.注册ControllerBuilder(老板)和默认工厂(DefaultControllerFactory) 2.1默认工厂获取可以创建的Controller. 三.由于 ...

  7. JAVA基础学习之final关键字、遍历集合、日期类对象的使用、Math类对象的使用、Runtime类对象的使用、时间对象Date(两个日期相减)(5)

    1.final关键字和.net中的const关键字一样,是常量的修饰符,但是final还可以修饰类.方法.写法规范:常量所有字母都大写,多个单词中间用 "_"连接. 2.遍历集合A ...

  8. 重温WCF之消息契约(MessageContract)(六)

    对于SOAP来说主要由两部分构成Header和Body,他们两个共同构成了SOAP的信封,通常来说Body保存具体的数据内容,Header保存一些上下文信息或关键信息.比如:在一些情况下,具有这样的要 ...

  9. Pyqt QListWidget 展示系统环境变量

    今天学习了下Pyqt的 QListWidget 控件 我们先看下这个图片 这张图片就是典型的listWidget效果,我们今天就仿这样布局新建个ListWidget 在网上找了个关于QListWidg ...

  10. python threading编程中的LOCK和RLOCK(可重入锁)

    找到一本PYTHON并发编辑的书, 弄弄.. #!/usr/bin/env python # -*- coding: utf-8 -*- import threading import time sh ...