fork download
  1. using System;
  2. // Thanks to:
  3. // http://b...content-available-to-author-only...x.net/2013/08/deterministic-miller-rabin-primality.html
  4. // https://g...content-available-to-author-only...b.com/softwx/SoftWx.Numerics
  5.  
  6. namespace ConsoleApp1
  7. {
  8. // Найдите все натуральные n ∈ (0..1000), такие что 2ⁿ - n кратно 7.
  9. // Find all natural numbers n ∈ (0..1000) such that 2ⁿ - n is a multiple of 7.
  10. class Program
  11. {
  12. // эта функция возвращает value ^ exponent % modulus
  13. static uint ModPow(uint value, uint exponent, ushort modulus)
  14. {
  15. uint result = 1;
  16. if ((exponent & 1) != 0) result = value;
  17. while ((exponent /= 2) != 0)
  18. {
  19. value = value * value % modulus;
  20. if ((exponent & 1) != 0)
  21. result = result * value % modulus;
  22. }
  23. return result;
  24. }
  25.  
  26. static void Main()
  27. {
  28. for (uint i = 1; i < 1000; ++i)
  29. if (ModPow(2, i, 7) == i % 7)
  30. Console.Write(i + "\t");
  31. // Console.ReadKey(true);
  32. }
  33. }
  34. }
  35.  
Success #stdin #stdout 0.02s 14760KB
stdin
Standard input is empty
stdout
11	15	16	32	36	37	53	57	58	74	78	79	95	99	100	116	120	121	137	141	142	158	162	163	179	183	184	200	204	205	221	225	226	242	246	247	263	267	268	284	288	289	305	309	310	326	330	331	347	351	352	368	372	373	389	393	394	410	414	415	431	435	436	452	456	457	473	477	478	494	498	499	515	519	520	536	540	541	557	561	562	578	582	583	599	603	604	620	624	625	641	645	646	662	666	667	683	687	688	704	708	709	725	729	730	746	750	751	767	771	772	788	792	793	809	813	814	830	834	835	851	855	856	872	876	877	893	897	898	914	918	919	935	939	940	956	960	961	977	981	982	998