XDOJ 1201: Dogs of Qwordance Senior Backend R&D Engineers

XDOJ 1201: Dogs of Qwordance Senior Backend R&D Engineers

题目链接:http://acm.xidian.edu.cn/problem.php?id=1201

题目大意:已知长宽均为整数的矩形面积为$n$,现要在该矩形上划上水平和垂直间隔为相同整数的网格,问有多少种方案.

组合数

若将数$x$按素因数分解,可以得到$x=\prod_{i=0}^kp_i^{c_i}$,从而有$\tau(x)=\prod_{i=0}^k(c_i+1)$,其中$\tau(x)$为$x$的因子数.

由题意得到,方案数为$\sum_{d|n}\tau(d) \times \tau(n/d)=\prod_{i=0}^k(\sum_{j=0}^{c_i}(j+1)(c_i-j+1))$.

注意素因数分解时,需要预处理$\sqrt{n}$内的素数,使原本$O(\sqrt{n})$的分解复杂度降为$O(\pi(\sqrt{n}))$,即$O(\frac{\sqrt{n}}{lnn})$.

代码如下:

 1 #include <iostream>
 2 #define N 1000005
 3 using namespace std;
 4 typedef long long ll;
 5 ll n,p[N],k,ans;
 6 bool v[N];
 7 void prime(){
 8     v[1]=1;
 9     for(ll i=2;i<N;++i){
10         if(!v[i])p[k++]=i;
11         for(ll j=0;j<k&&p[j]*i<N;++j){
12             v[p[j]*i]=1;
13             if(i%p[j]==0)break;
14         }
15     }
16 }
17 int main(void){
18     std::ios::sync_with_stdio(false);
19     prime();
20     while(cin>>n){
21         ans=1;
22         for(int i=0;p[i]*p[i]<=n;++i)if(n%p[i]==0){
23             ll tot=0,t=0;
24             while(n%p[i]==0){
25                 tot++;
26                 n/=p[i];
27             }
28             for(ll j=0;j<=tot;++j)
29                 t+=(j+1)*(tot-j+1);
30             ans*=t;
31         }if(n!=1)ans*=4;
32         cout<<ans<<"\n";
33     }
34 }
时间: 2024-07-30 13:45:25

XDOJ 1201: Dogs of Qwordance Senior Backend R&D Engineers的相关文章

xdu2017校赛F

Problem F Dogs of Qwordance Senior Backend R&D Engineers 问题描述 那年夏天,锘爷和杰师傅漫步在知春公园的小道上.他们的妻子.孩子牵 着狗在前面嬉戏,二人笑语盈盈,他们不深究一个小的编程问题,而是对整个 Qwordance (四字舞蹈)公司的发展前景加以描绘.这样的场景,想想就觉得好 美,想想就好向往,想想就好激动.然而,他们的狗觉得这非常的无聊,决定自 己去玩. 杰师傅的狗非常挑剔.它希望找到一块面积为 x 的长方形广场,还要求广 场的长

Building [Security] Dashboards w/R &amp; Shiny + shinydashboard(转)

Jay & I cover dashboards in Chapter 10 of Data-Driven Security (the book) but have barely mentioned them on the blog. That’s about to change with a new series on building dashboards using the all-new shinydashboard framework developed by RStudio. Whi

USACO 5.4.2 以后在理解

这道题的意思是到现在理解的不太透彻, 以后需要在看,  先把代码贴上吧 /* ID: m1500293 LANG: C++ PROG: charrec */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const char letter[30] = " abcdefghijklmnopqrstuvwxyz"; int ans[1201];

python regularexpress

这个正则表达式,我还真没有接触过,在python首次学习 //test.py 1 import re 2 3 print (re.match('www', 'www.myweb.com').span()) 4 print (re.match('com', 'www.myweb.com')) 5 6 line = 'Cats are smarter than dogs' 7 matchObj = re.match(r'(.*) are (.*?) (.*?) (.+)', line, re.M|r

python regularexpress1

//test.py 1 import re 2 3 print (re.search('www', 'www.myweb.com').span()) 4 print (re.search('com', 'www.myweb.com').span()) 5 6 line = 'Cats are smarter than dogs' 7 #matchObj = re.search(r'(.*) are (.*?) (.*?) (.+)', line, re.M|re.I) 8 #matchObj =

Oracle_linux_lesson_p2

用户和组 组:groupadd -g 1100 dbagroupadd -g 1200 oinstall 用户useradd -u 1100 -g 1200 -G 1100 -d /home/oracle oracle 查看oracle用户id oracle 改组名groupmod -n osdba #新用户 dba #老用户 用户改组名usermod -G 1201 1100 oracle 删除用户userdel -r testgroupdel dbagroupdel oinstall 改密码

python-网络安全编程第三天(正则表达式)

python 正则表达式 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序媛们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引擎执行. 用法 match() re.match()尝试从字符串的其实位置匹配一个模式匹配失败返回none语法:re.match(pattern,string,flags=00)pattern 匹配的正则表达式string 要匹配的字符串flags 标志位,控制正则表达式的匹配方式 1

xdoj

1000.a+b. #include<bits/stdc++.h> using namespace std; int a,b; int main() { ios::sync_with_stdio(false); while(cin >> a >> b) cout << a+b << endl; return 0; } 1001.直接开数组回爆内存,于是自己开个一维数组存放元素,大小需要自己斟酌.(或者动态数组) 直接处理对应位置,根据最后对应的位

hdu 6166 Senior Pan

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6166 题目: Senior Pan Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 245    Accepted Submission(s): 71 Problem Description Senior Pan fails i