记录编号 |
237370 |
评测结果 |
AAAAAAAAAA |
题目名称 |
无关的数 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.104 s |
提交时间 |
2016-03-17 08:28:29 |
内存使用 |
0.70 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long LL;
int n, m;
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a%b);
}
LL lgcd(LL a, LL b) {
return b == 0 ? a : gcd(b, a%b);
}
int ntoc[10], tot;
void out(int num) {
tot = 0;
while(num) {
ntoc[++tot] = num%10+'0';
num /= 10;
}
while(tot) {
putchar(ntoc[tot]);
tot--;
}
}
int sol[100005];
int cnt;
LL up, down;
void handle1(int x) {
while(! (x % m)) {
up *= m;
x /= m;
}
int tmp = gcd(x, m);
while(tmp != 1 && x != 1) {//tmp == 1 意味着两个数没有最大公约数
up *= tmp;
x /= tmp;
tmp = gcd(x, m);
}
}
void handle2(int x) {
while(! (x % m)) {
down *= m;
x /= m;
}
int tmp = gcd(x, m);
while(tmp != 1 && x != 1) {
down *= tmp;
x /= tmp;
tmp = gcd(x, m);
}
}
int main() {
freopen("irre.in", "r", stdin);
freopen("irre.out", "w", stdout);
scanf("%d %d", &n, &m);
up = 1; down = 1;
LL tmp;
for(int i = 2; i < n; i++) {
handle1(n-i+1);
handle2(i-1);
if(up % down) {
up /= down;
down = 1;
}
tmp = lgcd(up, down);
while(tmp != 1 && up != 1 && down != 1) {
up /= tmp;
down /= tmp;
tmp = gcd(up, down);
}
if(lgcd(up, (long long)m) == m) {
sol[++cnt] = i;
}
}
printf("%d\n",cnt);
for(int i = 1 ; i <= cnt; i++) {
out(sol[i]);
putchar(' ');
}
return 0;
}