规律题-3

来源:互联网 发布:c语言if并列多个条件 编辑:程序博客网 时间:2021/03/09 12:21
#include<bits/stdc++.h>using namespace std;const int maxn=1e9;int main(){    int nn,mm;    while(scanf("%d%d",&nn,&mm)!=EOF)    {    int n,m;n=min(nn,mm);m=max(nn,mm);    int rn=sqrt(n),rm=sqrt(m);    int cn=n-rn*rn,cm=m-rm*rm;    if(cn!=0) rn+=1;if(cm!=0) rm+=1;    if(cn==0) cn=2*rn-1;if(cm==0) cm=2*rm-1;    if(rn==rm){printf("%d\n",cm-cn);continue;}    int ans=(rm-rn-1)*2;    if(cn%2) ans+=1;    else ans+=2;    if(cm%2) ans+=1;    //cout<<ans<<endl;/*计算在第n行不移动的情况穿的边数,下面代码计算在第n行需要移动的步数*/    int _n=rm-rn;    if(cn%2==0) n+=1;    int a1=1+(rn-1)*2,a11=1+rn*2;    int c1=a1*_n+_n*(_n-1),c2=a11*(_n)+_n*(_n-1);    while(1)    {          int s1=n+c1,s2=n+c2;          //cout<<s1<<" "<<s2<<endl/*三角形在m行的边界*/           if(m>=s1&&m<=s2){break;}          else if(m<s1)          {              ans+=2;              n-=2;          }          else if(m>s2)          {              ans+=2;              n+=2;          }    }    printf("%d\n",ans);    }    return 0;}

Delta-wave

#include<bits/stdc++.h>//打印1!-500!就知道了using namespace std;const int N=1e5;int num[10]={5,25,125,625,3125,15625,78125,390625};int a[N+100];void init(){for(int i=5;i<=500000;i+=5){int cn=0;for(int j=0;j<8;j++) {cn+=i/num[j];}if(cn>100000) break;a[cn]=i;}}int main(){init();int m;while(scanf("%d",&m)!=EOF){if(a[m]==0) {printf("0\n");}else {printf("5\n");for(int i=a[m];i<a[m]+5;i++) printf("%d ",i);printf("\n");}}return 0;}
A Trivial Problem

0 0
原创粉丝点击