LightOJ 1236 Pairs Forming LCM【整数分解】
题目链接:
http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1236
题意:
找与n公倍数为n的个数。
分析:
依然是整数分解的问题。找到每个数的质因子,组合一下就好。
注意两个数中,对于每一个质因子,至少有一个数的该质因子的幂数与n相同。。所以每个质因子有2∗(b+1)−1种可能。
最后不要忘记加上1∗n的情况。。
代码:
#include <iostream>
using namespace std;
const int maxn = 1e7 + 5, maxm = 7e5 + 5;
bool flag[maxn];
int prime[maxm];
typedef long long ll;
int tot = 0;
void getprime()
{
fill(flag, flag + maxn, true);
for(int i = 2; i < maxn; i++){
if(flag[i]){
prime[tot++] = i;
for(int j = 2 * i; j < maxn; j += i){
flag[j] = false;
}
}
}
}
int main (void)
{
getprime();
int T;cin>>T;
ll n;
int cas = 1;
int cnt;
while(T--){
cin>>n;
ll ans = 1;
for(int i = 0; i < tot && prime[i] * prime[i]<= n; i++){
cnt = 0;
while(n % prime[i] == 0){n /= prime[i]; cnt++;}
ans *= (2 * cnt + 1);
}
if(n > 1) ans *= 3;
ans++;
cout<<"Case "<<cas<<": "<<ans / 2<<endl;
cas++;
}
return 0;
}
LightOJ 1236 Pairs Forming LCM【整数分解】的更多相关文章
- LightOJ 1236 Pairs Forming LCM 合数分解
题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...
- LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS Memor ...
- LightOJ 1236 - Pairs Forming LCM(素因子分解)
B - Pairs Forming LCM Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i, j)满足 LCM(i, j) = n, ...
- LightOJ - 1236 - Pairs Forming LCM(唯一分解定理)
链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...
- LightOj 1236 Pairs Forming LCM (素数筛选&&唯一分解定理)
题目大意: 有一个数n,满足lcm(i,j)==n并且i<=j时,(i,j)有多少种情况? 解题思路: n可以表示为:n=p1^x1*p2^x1.....pk^xk. 假设lcm(a,b) == ...
- 1236 - Pairs Forming LCM
1236 - Pairs Forming LCM Find the result of the following code: long long pairsFormLCM( int n ) { ...
- Light oj 1236 - Pairs Forming LCM (约数的状压思想)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...
- 1236 - Pairs Forming LCM -- LightOj1236 (LCM)
http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...
随机推荐
- 【python之路36】进程、线程、协程相关
线程详细用法请参考:http://www.cnblogs.com/sunshuhai/articles/6618894.html 一.初始多线程 通过下面两个例子的运行效率,可以得知多线程的速度比单线 ...
- CSS中position和header和overflow和background
<!DOCTYPE html> <!--CSS中position属性--> <html lang="en"> <head> < ...
- bzoj 1029 [JSOI2007]建筑抢修——贪心(伪dp)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1029 当然要按结束时间排序,然后按顺序修或跳过.就是那种“……不会使答案不优”的证明. 想了 ...
- TZ_01MyBatis_jdbcConfig.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=GMT jd ...
- warning: deprecated conversion from string constant to 'char*
warning: deprecated conversion from string constant to 'char* #include<iostream> using namespa ...
- cookie记录
登录页面引用: <script src="/jquery.cookie.js"></script> 登录页面jq: var telphone = $('[n ...
- RHEL7系统安装方式
RHEL7系统安装方式包括: 1. 手动安装(介质在本地): 此种方式你可以通过图形界面操作定制你所需安装系统的配置及所需软件包等 优点:直观 缺点:效率低下,配置的东西多时易犯错 此种方式仅适用于初 ...
- oracle创建定时任务
一.dmbs_job dbms_job涉及到的知识点 1.创建job: variable jobno number; dbms_job.submit(:jobno, —-job号 'your_pro ...
- Python实例 复制文件
import shutil import os import os.path src = " d:\\download\\test\\myfile1.txt " dst = ...
- Leetcode657.Robot Return to Origin机器人能否返回原点
在二维平面上,有一个机器人从原点 (0, 0) 开始.给出它的移动顺序,判断这个机器人在完成移动后是否在 (0, 0) 处结束. 移动顺序由字符串表示.字符 move[i] 表示其第 i 次移动.机器 ...