zoukankan      html  css  js  c++  java
  • Codeforces 453B. Fedya and Maths

    Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:

    (1^n + 2^n + 3^n + 4^nmod 5

    for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).

    Input

    The single line contains a single integer n (0 ≤ n ≤ 10^(10^5)). The number doesn't contain any leading zeroes.

    Output

    Print the value of the expression without leading zeros.

    从输入就知道肯定得找规律

    使用广义欧拉定理简化

      a^b≡a^(b%φ(m)+φ(m))(mod m)   (b > φ(m) )  
    易得在此题中只有顶多φ(5)=4种情况,全部算出来后分别是4,0,0,0,其中4在n整除4时得到,所以问题便变成了判断该数是否整除4
    也就是末尾两位数是否整除4
    #include <cstdio>
    #include <cctype>
    #include <stdlib.h>
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <map>
    
    using namespace std;
    typedef long long LL;
    
    char s[100005];
    int main()
    {
      // freopen("test.in","r",stdin);
      cin >> s;
      int len = strlen(s);
      int now = 0,base = 1;
      for (int i=len-1;i>=max(0,len-2);i--){
        now += base * (s[i] - '0');
        base *= 10;
      }
      if (now % 4){
        cout << 0;
      }
      else
        cout << 4;
      return  0;
    }
    View Code
  • 相关阅读:
    Servlet监听器及在线用户
    数据分页jdbc+mysql实现
    使用ajax验证用户名重复
    Mysql中的事务
    用户登录注册案例分析
    Java连接mysql数据库
    Java连接sqlite数据库
    虚拟主机TOMCAT配置
    用jquery控制表格奇偶行及活动行颜色
    JDK安装后 没有tools.jar 和dt.jar包的解决办法
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6856548.html
Copyright © 2011-2022 走看看