数论基础

数论基础

#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
typedef long long ll;
ll su[10010];
bool issu[10010];
#define N 10000
/*快速幂*/
 ll Pow(int a,int b)
{
    int base = a;
    ll ans = 1;
    while(b)
    {
        if(b&1) ans*=base;
        base *=base;
        b>>1;
    }
    return ans;
}
/*六倍法判素数*/
bool isPrime(int a)
{
  if(a == 1) return false;
  if(a == 2||a == 3||a ==5) return true;
  if(a%2 == 0||a%3 == 0) return false;
  for(int i=5;i*i<=a;i+=6)
  {
      if(a%i == 0 || a%(i+2) == 0)
        return false;
  }
  return true;
}
/*欧拉筛*/
ll Prime(ll n)
{
    ll cnt = 0;
    for(ll i=2;i<=n;i++){
        if(!issu[i])
            su[++cnt] = i;
        for(ll j =1;j<=n&&su[j]*i<=n;j++){
            issu[su[j]*i] = 1;
            if(i%su[j]==0) break;
        }
    }
    return cnt;
}

int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int icm(int a,int b)
{
    return a/gcd(a,b)*b;
}
int huiwen(int n)
{
    int m = n,t = 0;
    while(m)
    {
        t = t*10+m%10;
        m/=10;
    }
    return n==m?1:0;
}
void zhiyinsu(ll n)
{
    Prime(n);
    ll i = 1;
    ll cnt = 0;
    while(n != n)
    {
        if(n%i == 0){
            printf("%d ",su[i]);
            cnt++;
            if(cnt == 10){
                printf("\n");
                cnt = 0;
            }
            n/=su[i];
            continue;
        }
        i++;
    }
}
int main()
{
    zhiyinsu(N);
    return 0;
}
#include <iostream>
#include <string>

using namespace std;
int mon[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int cntD,cntM,cntW,cnt;
int ans,y = 2000,m = 1,d = 1,week = 6;
int main()
{
    while(1)
    {
        cntD++;
        if(d == 1) cntM++;
        if(week == 1) cntW++;
        if(d == 1&&week == 1) cnt++;
        if(d == 1||week == 1) ans+=2;
        else ans++;
        if(y == 2020&&m ==10&&d ==1) break;

        if((y%4 == 0&&y%100 !=0)||y%400 ==0) mon[2] = 29;
        else mon[2] = 28;

        if(d == mon[m]){
            if(m ==12){
                m = 1;
                d = 1;
                y++;
            }
            else{
                m++;
                d = 1;
            }
        }
        else d++;
        if(week == 7) week =1;
        else week++;
    }
    cout<<cntD<<endl;
    cout<<cntM<<endl;
    cout<<cntW<<endl;
    cout<<cnt<<endl;
    cout<<ans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值