ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 A. Anagrams
1 second
512 megabytes
standard input
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.
The only line of the input contains an integer b — the base of the given positional numeral system (2 ≤ b ≤ 2·109).
Print all b-stable integers k represented in the standard decimal numeral system. They must be printed in ascending order.
3
1 2
9
1 2 4 8
33
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- Moscow Subregional 2013. 部分题题解 (6/12)
Moscow Subregional 2013. 比赛连接 http://opentrains.snarknews.info/~ejudge/team.cgi?contest_id=006570 总叙 ...
随机推荐
- Maven中手动引用第三方jar包
有些jar包在Maven库中并不支持,但我们又需要.所以就必须手动引入. 可分为三步完成: 1 ,在项目目录下创建Lib,把引入的jar包加入. 2.在pom.xml中引入dependences. 如 ...
- java web统计当前访问用户数量
1.使用SessionListener监听器,监听创建与销毁session的操作,利用计数方式记录当前session的数量
- nyoj744(位运算)
题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=744 思路:a^b可以得到a~b间任意两个数异或运算的长度的最大值,设为n,答案为:pow(2 ...
- 我的JavaEE学习路线图
从学习Java开发到现在虽然也已经快三年了,但是要说到分享一下经验实在是不敢当.权当是对自己的一个总结吧,希望大家不吝指教,互相交流. 照旧,还是现来整理一下我学习Java的一个路线图吧,然后按照这个 ...
- windows 下的tcping 小插件
如果把插件放在根目录 就要能过cmd切换到根目录 cd \ c:\>tcping -d -t -i 0.06 www.baidu.com 将文件放在c:\WINDOWS\system32目录下, ...
- Linux安装mysql最新版本纪要
http://blog.csdn.net/frt007/article/details/50184143 http://blog.csdn.net/wb96a1007/article/details/ ...
- Delphi中线程类TThread实现多线程编程2---事件、临界区、Synchronize、WaitFor……
接着上文介绍TThread. 现在开始说明 Synchronize和WaitFor 但是在介绍这两个函数之前,需要先介绍另外两个线程同步技术:事件和临界区 事件(Event) 事件(Event)与De ...
- python中的monkey-patching
这个技巧我很少用过. 但知道无防. 在运行时改变函数或类的行为, 一般用猴子补丁,原类,装饰器都可以实现. #!/usr/bin/env python # -*- coding: utf-8 -*- ...
- 第一部分:使用iReport制作报表的详细过程(Windows环境下)
提示:在有些板块,文中的图片看不到,建议到我的blog浏览文章:http://blog.csdn.net/jemlee2002/文章将会涉及3个方面的内容: 第一部分:使用iReport制作报表的详细 ...
- linux文本模式下使用PPPOE拨号ADSL上网的方法
转自:http://www.myzhenai.com.cn/post/945.html 转载请注明出处:http://www.myzhenai.com/thread-15431-1-1.html ht ...