第一题给定一个大数,分解质因数,每个质因子的个数为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的更多相关文章

  1. Light oj 1236 - Pairs Forming LCM (约数的状压思想)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...

  2. LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memor ...

  3. 1236 - Pairs Forming LCM

    1236 - Pairs Forming LCM   Find the result of the following code: long long pairsFormLCM( int n ) {  ...

  4. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  5. LightOJ 1236 - Pairs Forming LCM(素因子分解)

    B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  6. LightOJ - 1236 - Pairs Forming LCM(唯一分解定理)

    链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...

  7. LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i,  j)满足 LCM(i, j) = n, ...

  8. 1236 - Pairs Forming LCM -- LightOj1236 (LCM)

    http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...

  9. LightOJ 1236 Pairs Forming LCM 合数分解

    题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...

随机推荐

  1. 某p2p存在通用上传漏洞

    google链接查找: inurl:shouyi.asp inurl:itemlist_xq.asp?id= 很多存在Fckeditor上传链接: FCKeditor/editor/filemanag ...

  2. Django-【views】decorators.csrf

      views下导入方法 from django.views.decorators.csrf import csrf_exempt,csrf_protect csrf_exempt是全局需要,唯独这个 ...

  3. Linux-进程间通信(四): 域套接字

    1. 域套接字: (1) 只能用于同一设备上不同进程之间的通信: (2) 效率高于网络套接字.域套接字仅仅是复制数据,并不走协议栈: (3) 可靠,全双工: 2. 域套接字地址结构: struct s ...

  4. java===java基础学习(11)---继承

    继承可以解决代码复用,让编程更加靠近人的思维.当多个类存在相同的属性(变量)和方法时,可以从这些类中抽象出父类,在父类中定义这些相同的属性和方法.所有的子类不需要重新定义这些属性和方法,只需要通过ex ...

  5. java===java基础学习(1)---数据类型,运算,变量,常量

    今天起开始了java的学习之路,主要学习了数据类型和运算,变量,常量.基本和python有很多相通的地方,所以看起来很容易上手.下面是学习笔记! package testbotoo; public c ...

  6. 内核抢占实现(preempt) 【转】

    转自:http://blog.chinaunix.net/uid-12461657-id-3353217.html 一.什么叫抢占所谓抢占,说白了就是进程切换.linux的用户空间,进程A在执行中,来 ...

  7. 单从软件层面来说,Maya 和 Blender 差别在哪?

    单从软件层面来说,Maya 和 Blender 差别在哪? https://www.zhihu.com/question/21975571

  8. 设计模式之笔记--建造者模式(Builder)

    建造者模式(Builder) 定义 建造者模式(Builder),将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 类图 描述 Builder:定义一个建造者抽象类,以规范产 ...

  9. MyBatis批量插入数据(MySql)

    由于项目需要生成多条数据,并保存到数据库当中,在程序中封装了一个List集合对象,然后需要把该集合中的实体插入到数据库中,项目使用了Spring+MyBatis,所以打算使用MyBatis批量插入,应 ...

  10. C++11空指针: nullptr

    参考[C++11]新特性--引入nullptr NULL 在C++中, 经常会用到空指针, 一般用NULL表示空指针, 但是NULL却是这样定义的 #ifndef NULL #ifdef __cplu ...