摘要: #include using namespace std; // ofstream __f("E:/123.txt"); // #define cout __f //括号判断准则 // 括号前边为 “ - ”,且括号中为 “ + ” 或 “ - ”,不能删除; // 括号前边为 “ / ”,不能删除; // 括号后为 “ * ”,且括号中为 “ + ” 或 “ - ”,不能删除; // 有以... 阅读全文
posted @ 2020-06-06 21:43 西伯利亚挖土豆 阅读(241) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; //用bfs以为找到一个解就是最优的,类似于走迷宫 //不需要清除hash,因为这就是在状态图上进行bfs,隐式图,没法vis数组 typedef pair pp; const int mod=1000003; int ans=0x3f3f3f3f,d[][2]={{1,0},{-1,0},{0,1},{0,-1}},n,nx,ny;/... 阅读全文
posted @ 2020-06-06 21:43 西伯利亚挖土豆 阅读(147) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; //快速求幂,就是二分法 long long mod=1000000007L; long long pow1(int x,int y){ //判断奇偶,偶数返回0奇数返回1 if(y==0) return 1; long long q=pow1(x,y/2);//注意只调用一遍,否则On if(y&1) ... 阅读全文
posted @ 2020-06-06 21:42 西伯利亚挖土豆 阅读(176) 评论(0) 推荐(1) 编辑
摘要: #include <iostream> #include <cstdio> using namespace std; int s=0; int f(int x){ int i=2,res=1;//因为x可能为1.。。。 while (x>1) { if(x%i==0){ //这里实际上是使劲除,除干净的方式,因为i没有++ x=x/i; res=i; s++; }else { i++; s=0; 阅读全文
posted @ 2020-06-06 21:39 西伯利亚挖土豆 阅读(430) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int a=100,b=20; int gcd(int a,int b){ return b==0?a:gcd(b,a%b); //注意最好先除再乘,否则可能溢出.因为a肯定可以被gcd整除 } int lcm(int a,int b){ return a/gcd(a,b)*b; } //gcd应用: //判断 (x 阅读全文
posted @ 2020-06-06 21:38 西伯利亚挖土豆 阅读(151) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; typedef long long ll; //求小数点后第n位,很容易想到(a*10^(n+2)/b)%1000,即可得到数值,注意输出的时候左边补充0 //但是a*10^(n+2)太大了,long long 溢出了,利用公式x/d%m = (x%(d*m)/d)%m,直接获得等价类 //得到,((a*10 阅读全文
posted @ 2020-06-06 21:37 西伯利亚挖土豆 阅读(239) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include <cstdio> using namespace std; long long x; //使用公式 int f1(){ int s=1; long long xx=x,i=2; int count1=0,flg=0; while (xx>1) { if(xx%i==0){ xx=xx/i; count1++; }else{ i++; if( 阅读全文
posted @ 2020-06-06 21:37 西伯利亚挖土豆 阅读(121) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; //求逆元,方法是费马小定理,还有一种更快的线性算法 long long mod=1000000007L; int pow_mod(int x,int y,int c){ if(y==0) return 1; int q=pow_mod(x,y/2,c)%c; if(y&1) return (q*q*x)%c 阅读全文
posted @ 2020-06-06 21:35 西伯利亚挖土豆 阅读(331) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include <cstdio> //阶乘的最后一个非0数 //即去掉因子5,2;计算乘积的个位 //乘积的个位=仅仅对每个数的个位进行乘积,每次都%10即可;连锁起来了 using namespace std; // int main(){ // int x,s=0,q=1; // cin>>x; // for(int i=2;i<=x;i++){ // 阅读全文
posted @ 2020-06-06 21:34 西伯利亚挖土豆 阅读(296) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; long long n; int main() { while(cin>>n){ //求素因子分解,加速原理,所有的数,如果有比sqrt(n)大的素因子,最多只有1种,1个 long long s=0,t=2,sq=(long long)sqrt(n); while(n>1){ while(n%t==0){ 阅读全文
posted @ 2020-06-06 21:34 西伯利亚挖土豆 阅读(165) 评论(0) 推荐(0) 编辑