思路:

这题有个结论也可以自己归纳:

对于给定的n,其约数用pi表示

T(n)=T(p1)T(p2)……T(pn)T(n')

其中T(n')是这个式子所独有的也就是

T(n')=(x^n-1)/T(p1)/T(p2)……/T(pn)

代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#define MAX 1102
using namespace std;
struct pol
{
int bit[MAX],len;
void init(){memset(bit,,sizeof(bit));len=;}
}p[MAX];
int ans[MAX];
int com(pol a,pol b)
{
if(a.len!=b.len)return a.len-b.len;
for(int i=a.len-;i>=;i--)
if(a.bit[i]!=b.bit[i]){
if(abs(a.bit[i])!=abs(b.bit[i]))
return abs(a.bit[i])-abs(b.bit[i]);
return a.bit[i]-b.bit[i];
}
return ;
}
bool cmp(int a,int b)
{
return com(p[a],p[b])<;
}
void shows(int n)
{
if(n>) printf("x^%d",n);
else if(n==) printf("x");
}
void show(pol a)
{
int x;
printf("(");
for(int i=a.len-;i>=;i--){
if(a.bit[i]==) continue;
if(i==){
if(a.bit[i]>) printf("+%d",a.bit[i]);
else printf("%d",a.bit[i]);
continue;
}
if(i==a.len-){
if(a.bit[i]<) printf("-");
x=abs(a.bit[i]);
if(x>) printf("%d",x);
shows(i);
continue;
}
if(a.bit[i]<) printf("-");
else printf("+");
x=abs(a.bit[i]);
if(x>) printf("%d",x);
shows(i);
}
printf(")");
}
pol Div(pol a,pol b)
{
pol c;
c.init();
for(int i=a.len-;i>=;i--)
if(a.bit[i]){
c.bit[i-b.len+]=a.bit[i];
int cnt=,cur=a.bit[i];
for(int j=b.len-;j>=;j--){
a.bit[i-cnt]-=cur*b.bit[j];
cnt++;
}
}
c.len=a.len;
while(c.len>&&c.bit[c.len-]==) c.len--;
return c;
}
int main(){
p[].bit[]=-;
p[].bit[]=;
p[].len=;
for(int i=;i<MAX;i++){
p[i].init();
p[i].bit[i]=;p[i].bit[]=-;
p[i].len=i+;
p[i]=Div(p[i],p[]);
for(int j=;j*j<=i;j++){
if(i%j==){
p[i]=Div(p[i],p[j]);
if(j*j!=i) p[i]=Div(p[i],p[i/j]);
}
}
}
int n,m;
while(scanf("%d",&n)&&n){
if(n==){
puts("x-1");
continue;
}
m=;
for(int i=;i*i<=n;i++){
if(n%i==){
ans[m++]=i;
if(i*i!=n) ans[m++]=n/i;
}
}
sort(ans,ans+m,cmp);
for(int i=;i<m;i++)
show(p[ans[i]]);
printf("\n");
}
return ;
}

hdu 4447 Yuanfang, What Do You Think?的更多相关文章

  1. HDU P4578 Transformation

    Problem Description Yuanfang is puzzled with the question below: There are n integers, a1, a2, …, an ...

  2. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  3. HDU 4578 - Transformation - [加强版线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is puzzled with the ...

  4. HDU 4578 线段树玄学算法?

    Transformation 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is p ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. NSURLConnection ignore unverified certificate error when sending a synchronise request

    Private API, use with caution. As we all know, it's easy to ignore the unverified certificate error ...

  2. 8.samba server与client配置

    server端 1.安装samba:yum install -y samba\* 增加samba用户: useradd smb用户名               smbpasswd -a smb用户名 ...

  3. Fedora 20 创建桌面快捷方式

    创建desktop文件 sudo touch /usr/share/applications/sublime.desktop 添加内容 [Desktop Entry] Encoding=UTF-8 N ...

  4. php关联不上mysql解决办法

      ## php无法关联mysql  php关联不上mysql解决办法: 尝试N多方法,需要的dll文件都复制了,依旧是不断提示: Fatal error: Call to undefined fun ...

  5. Hadoop上路-04_HBase0.98.0入门

    以下操作在Hadoop分布式集群基础上进行. 一.分布式环境搭建 下载:)验证 3)修改%HBASE%/conf/hbase-env.sh 4)修改$HBASE_HOME/conf/hbase-sit ...

  6. localStorage变更事件当前页响应新解

    html5的localStorage相信大家都是很熟悉了,但是在chrome等支持该对象的浏览器中(ie10除外),如果你监听 storage变更事件你就会发现,当数据发生变化时本页是监听不到stor ...

  7. 利用ajax在javascript中获取后台的值

    <script type="text/javascript"> function login() { var sa = WebForm1.Hello().value; ...

  8. Hive基本命令整理

    创建表: hive> CREATE TABLE pokes (foo INT, bar STRING);          Creates a table called pokes with t ...

  9. mysqldump 参数说明

    mysqldump参数说明 --all-databases , -A 导出全部数据库. mysqldump -uroot -p --all-databases --all-tablespaces , ...

  10. 解决sublime text 2总是在新窗口中打开文件

    在mac下不是很喜欢sublime text 2 总是在新窗口中打开文件,很麻烦,文件打多了,就会出现N多窗口,虽然可以直接打开当前目录可以解决,但有时候查看其它项目中的单个文件,就比较麻烦.百度一直 ...