4 条题解
-
0
最多平方两次,个位就开始重复,所以也可以用循环。
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); long x=sc.nextLong(); long m= sc.nextLong(); x=x%10; for(int i=0;i<2&&i<m;i++){//防止m=1情况 x=(x*x)%10;//求个位 } System.out.println(m*x); } }
-
0
打表可知最多平方三次,后面就开始重复
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' void solve(); int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; } void solve(){ ll x,m; cin>>x>>m; for(int i=1;i<min(m,4ll);i++){ x*=x; x%=10; } cout<<x*m<<endl; }
-
0
蒟蒻写法 记得开long
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int m = sc.nextInt(); x %= 10; if(x == 1){ System.out.println((long)m); }else if(x == 2){ if(m >= 3){ System.out.println((long)m * 6); }else { for (int i = 0; i < m - 1; i++) { x *= x; } x %= 10; System.out.println((long)x * m); } } else if (x == 3) { if(m >= 3){ System.out.println((long)m); }else { for (int i = 0; i < m - 1; i++) { x *= x; } x %= 10; System.out.println((long)x * m); } } else if(x == 4){ if(m >= 2){ System.out.println((long)m * 6); }else System.out.println((long)4 * m); }else if(x == 5){ System.out.println((long)5 * m); }else if(x == 6){ System.out.println((long) 6 * m); }else if(x == 7){ if(m >= 3){ System.out.println((long)m); }else { for (int i = 0; i < m - 1; i++) { x *= x; } x %= 10; System.out.println((long)x * m); } }else if(x == 8){ if(m >= 3){ System.out.println((long)6 * m); }else { for (int i = 0; i < m - 1; i++) { x *= x; } x %= 10; System.out.println((long)x * m); } }else if(x == 9){ if(m >= 2){ System.out.println((long)m); }else { System.out.println((long)9 * m); } }else System.out.println(0); } }
-
0
打表发现当m>一定值时,x不变化
#include <iostream> #include <vector> #include <set> using namespace std; #define int long long const int mod=1e+7; signed main() { iostream::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x,m;cin>>x>>m; x%=10; int n=m; while((x*x)%10!=x&&m>0){ x=(x*x)%10; m--; } cout<<x*n<<endl; return 0;//AC }
- 1
信息
- ID
- 587
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 708
- 已通过
- 44
- 上传者