随笔分类 - Math
The game for wise man!
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1141分析:运用欧拉函数可解此题。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #define LL long long12 using namespace std;13 int T;14 int n;15 int gcd(int a,int b)16 {17 if(b==0)return a;18...
阅读全文
摘要:题目:Sum原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4704分析:实际上就是求2^(n-1)mod(1e9+7).因为2与1e9+7互素,所以可以用费马小定理。参考:http://baike.baidu.com/view/263807.htm(a,p)=1,则a^(p-1)Ξ1(modp).可得:2^(n-1)%mod=2^((n-1)%(mod-1)) %mod;证明:(n-1)=(n-1)%mod+k*(mod-1).则:2^(n-1)=2^((n-1)%(mod-1)) * 2^(k*(mod-1));可知结论成立。 1 #inclu
阅读全文
摘要:一:埃拉托斯尼斯筛法. 1 #define maxn 1000000 2 bool isPrime[maxn+10]={true}; 3 int prime[maxn],k=0; 4 void selPrime() 5 { 6 isPrime[0]=isPrime[1]=false; 7 for(int i=2;i<=maxn;i++) 8 { 9 if(isPrime[i])10 {11 prime[k++]=i;12 ...
阅读全文
摘要:原题链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=117分析:设数为N,则其位数为(int)lg(N)+1;log(10)=ln(10);素数定理:令Pn表示 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int main() 8 { 9 int n;10 double e=2.71828;11 while(cin>>n)12 {13 double ans=double(n...
阅读全文
摘要:原题链接:http://acm.uestc.edu.cn/problems.php?vol=15分析:首先筛出sqrt(2^31-1)以内的素数,对于给定的区间[L,R],仍然用筛素数的思想把那些是前面筛选出来的素数的倍数的做标记,然后从左到右扫一遍即可。How many primes 1 #include 2 #include 3 #include 4 #include 5 #define maxn 100005 6 using namespace std; 7 int prime[maxn],t; 8 bool ans[1000005]; 9 bool flag[maxn]={false}
阅读全文

浙公网安备 33010602011771号