Number Theory (Easy) SPOJ - NUMTRYE(数论)(结论类)
2017-10-18 12:42
567 查看
f(n) and g(n) are two functions defined as following :
f(n)=∏(pi2ei+1+1), where pi is prime factor of n and ei is highest power of pi in n.
g(n)=Σ(ngcd(n,i)); 1 <= i <= n
For a given value of n, you have to compute f(n)/g(n) % 1000000007.
Input
First line has T ( <= 10000 ), next T lines has 2 <= n <= 10^12.
Output
f(n)/g(n) % 1000000007 for each test case.
Example
Input:
2
2
4
Output:
3
3
这个怎么说呢,一个结论吧,记住吧,但是不会证明
g(n)=∏p2ei+1i+1pi+1
所以f(n)g(n)=∏pi+1
f(n)=∏(pi2ei+1+1), where pi is prime factor of n and ei is highest power of pi in n.
g(n)=Σ(ngcd(n,i)); 1 <= i <= n
For a given value of n, you have to compute f(n)/g(n) % 1000000007.
Input
First line has T ( <= 10000 ), next T lines has 2 <= n <= 10^12.
Output
f(n)/g(n) % 1000000007 for each test case.
Example
Input:
2
2
4
Output:
3
3
这个怎么说呢,一个结论吧,记住吧,但是不会证明
g(n)=∏p2ei+1i+1pi+1
所以f(n)g(n)=∏pi+1
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #define N 1000500 #define mod 1000000007 using namespace std; typedef long long ll; bool tag ; vector<int> prime; void getPrime() { for(int i=2;i<N;i++) if(!tag[i]) { prime.push_back(i); for(int j=i+i;j<N;j+=i) tag[j]=true; } } ll fac[100]; int k; int getFac(ll x) { k=0; for(int i=0;(ll)prime[i]*prime[i]<=x;i++) { if(x%prime[i]==0) { fac[k++]=prime[i]; while(x%prime[i]==0) x/=prime[i]; } } if(x>1) fac[k++]=x; } ll solve() { ll ans=1; for(int i=0;i<k;i++) ans=ans*(fac[i]+1)%mod; return ans; } int main() { getPrime(); int t; ll n; scanf("%d",&t); while(t--) { scanf("%lld",&n); getFac(n); printf("%lld\n",solve()); } return 0; }
相关文章推荐
- 常用数论结论
- (one day one problem)SPOJ - PROD1GCD Product it again (GCD+分解质因子找思路)-数论
- ACM 数论 A problem is easy
- 玲珑杯1144 - 数论你还会快速幂【结论+快速乘】
- (SPOJ - ELIS )Easy Longest Increasing Subsequence(DP)
- number theory 基础数论
- BZOJ 2226 [Spoj 5971] LCMSum | 数论拆式子
- [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演
- spoj BCEASY - Bottom Coder (Easy)
- [number theory]数论
- SPOJ:Factorial Modulo(数论)
- SPOJ 5161 FACVSPOW - Factorial vs Power(数论+二分)
- SPOJ LCMSUM (数论)
- SPOJ-Grid ,水广搜easy bfs
- SPOJ:EXPOR - OR(数论)
- 【结论】【数论】拓展欧几里得算法、费马小定理
- BZOJ 2226: [Spoj 5971] LCMSum(数论+欧拉函数)
- MIT6-042J-FALL-2010 第四章 数论(Number Theory)
- SPOJ Thor vs Frost Giants 数论
- 数论 - Funny scales(SPOJ - SCALE)