light oj 1236 - Pairs Forming LCM & uva 12546 - LCM Pair Sum
第一题给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,……em,
则结果为((1+2*e1)*(1+2*e2)……(1+2*em)+1)/2.
代码如下:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#define M 10000005
#define mod 1000000007
#define ll unsigned long long
using namespace std;
ll prime[M/],cnt;
bool f[M];
void init()
{
int i,j;
cnt=;
for(i=;i<M;i++){
if(!f[i]) prime[cnt++]=i;
for(j=;j<cnt&&i*prime[j]<M;j++){
f[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
}
ll solve(ll n)
{
ll ans=;
for(ll i=;i<cnt&&(ll)prime[i]*prime[i]<=n;i++){
if(n%prime[i]==){
ll t=;
n/=prime[i];
while(n%prime[i]==){
t++;
n/=prime[i];
}
ans*=(ll)(+t*);
}
}
if(n>) ans=*ans;
return (ans+)/;
}
int main()
{
int t,ca=;
ll n;
init();
scanf("%d",&t);
while(t--){
scanf("%llu",&n);
printf("Case %d: %llu\n",++ca,solve(n));
}
return ;
}
第二题给定一个数N,其质因子pi及个数ei给定,
则结果为(1+p1+p1^2+……+p1^ei+ei*p1^ei)*……*(1+pm+pm^2+……+pm^em+em*pm^em)+N.
代码如下:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#define mod 1000000007
#define ll long long
using namespace std;
ll Pow(ll a,int b)
{
ll ans=;
while(b){
if(b&) ans=(ans*a)%mod;
b>>=;
a=(a*a)%mod;
}
return ans;
}
ll sum(ll a,int b)
{
if(b==) return ;
if(b&) return (+Pow(a,(b+)/))*sum(a,b/)%mod;
else return ((+Pow(a,b/+))*sum(a,b/-)%mod+Pow(a,b/))%mod;
}
int main()
{
int t,ca=,n,p,e;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
ll ans=,xx,num=;
for(int i=;i<n;i++){
scanf("%d%d",&p,&e);
xx=Pow(p,e);
num=(num*xx)%mod;
xx=(xx*e)%mod;
xx=(xx+sum(p,e))%mod;
ans=(ans*xx)%mod;
}
printf("Case %d: %lld\n",++ca,(ans+num)%mod);
}
return ;
}
light oj 1236 - Pairs Forming LCM & uva 12546 - LCM Pair Sum的更多相关文章
- Light oj 1236 - Pairs Forming LCM (约数的状压思想)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...
- LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS Memor ...
- 1236 - Pairs Forming LCM
1236 - Pairs Forming LCM Find the result of the following code: long long pairsFormLCM( int n ) { ...
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
- 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(唯一分解定理)
链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...
- LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i, j)满足 LCM(i, j) = n, ...
- 1236 - Pairs Forming LCM -- LightOj1236 (LCM)
http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...
- LightOJ 1236 Pairs Forming LCM 合数分解
题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...
随机推荐
- Runas replacement tool
1. RunAsSpc Runas 无法在脚本中输入密码,可以使用RunAsSpc替代. RunAsSpc = runas + password + encryption https://robotr ...
- Keil MDK 5.14 仿真时System Viewer菜单显示空白和Peripherals菜单无外设寄存器
keil mdk5.14新建工程进行仿真时,进入Debug环境发现System Viewer菜单显示空白,Peripherals菜单没有外设寄存器.如图1和图2所示.打开Oprons for Targ ...
- android 内核调试
这篇文档给出使用android emulator 和 arm-linux-androideabi-gdb 调试 android kernel 的方法 1. checkout goldfish 源码: ...
- nginx升级步骤
今天应开发的需求,需要在Nginx增加一个模块,并不能影响现有的业务,所以就必须要平滑升级Nginx,好了,不多说了 1:查看现有的nginx编译参数 /usr/local/nginx/sbin/ng ...
- jquery获取元素索引值index()的例子
如果参数是一组DOM元素或者jQuery对象,那么返回值就是传递的元素相对于原先集合的位置. 如果参数是一个选择器,那么返回值就是原先元素相对于选择器匹配元素中的位置.如果找不到匹配的元素,则返回-1 ...
- 去掉a标签的虚线框,避免出现奇怪的选中区域
a{blr:expression(this.onFocus=this.blur())}/*去掉a标签的虚线框,避免出现奇怪的选中区域*/
- jquery文档加载几种写法,图片加载写法
jquery文档加载写法: $(function(){ }) ; //个人最常使用方式 $(document).ready(function(){ }); //调用文档对象下的ready方法传入一个函 ...
- HDU-5335
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- Linux安装mysql.8.0.12
1. linux安装mysql8.0.12,亲测可用. 以下是安装过程中出现的问题: 1 [root@localtest1 file]# systemctl start mysqld 2 Job fo ...
- 【hdoj_2570】迷障
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2570 思路:贪心法.要求在浓度不超标的情况下,解药的最大体积.由于体积相同,可以先对浓度排序,然后从浓度小 ...